I created a form inside a block, and now I can place it in other blocks or directly on a page. So far, so good, but the problem is that when I click the “Save” button on the page, for example, the required fields in the form—which is inside the block—aren't triggering an error message. Is there any way to force the block containing the form to send error messages for the required fields?
Thank you all for your help. I decided to use JavaScript to click a hidden button in the block containing the form, and it’s working well. The hidden button checks the form's validity, which triggers the error messages. The block/page that calls the block containing the form runs the JavaScript on OnReady, and that's how the hidden button is clicked. Thanks again for the ideas and suggestions.
Hi @Leandro Seixas Duarte ,
can you explain in more detail how exactly the entire structure (parent + block) is built up and why. Where de you retrieve data, where do you edit data, where is the button to save and where do you save data.
The form validations when hitting a button with option 'Built in validations' set to yes, will only happen on the form that button sits in. From what you say, I get that the button is somewhere higher up in one of the parents of the block, so why would you make a form inside the block ?
Dorine
Hi @Dorine Boudry ,This block, containing the form, will be used in more than one place, which is why we put it in a block. And yes, the save button is located somewhere higher up. The form is primarily used to collect information, but editing and saving are performed on the pages that will display the block containing the form. What I need is to trigger the form validations “from the outside in,” meaning I need the page to be somehow able to click a button inside the block to trigger the “Built-in validations.” I’m following a tip from a friend who used a hidden button in the form and clicked it with JavaScript in the block’s OnReady event. But I’d prefer something more straightforward and with less JavaScript.
If the block only serves the purpose of presentation and ALL YOU WANT is making the built-in validations work, and the actual saving is delegated to the parent (I'm assuming each OnChange in the block triggers an event that passes the data to the parent) just put it inside a form at the parent level, not the block level.
So again the question, why is there a form in the block ? And even if you leave the form in the block, just putting the entire block IN THE SAME FORM as the save button (so you'd have a form in a form) would work. But I don't see the point of doing that, just remove the form at block level.
But you will have extra problems if you start adding custom validations. If you want those validations to be implemented in the parent when save button is clicked, you won't have access to the Valid properties of the widgets in the webblock from that spot.
So, your parent would also have to communicate stuff down to the block about what input is invalid, and what InvalidMessage to show with it.
I realize it would be simpler and easier to place the save button and the form in the same location so that the built-in validations would work without any issues, but my current situation doesn’t allow for that. To be more specific… I have a section of the main form implemented in a separate block, which contains the full address details. The product/business for which I’m developing this app requires a high level of complexity regarding the address, so we decided to put it in a separate block. However, this address block will be called in different forms on different pages. In this case, I can’t place the buttons and form on the same layer. If you have nothing else to add, I suggest you stop insisting that the solution is to place buttons and the form in the same location. Thank you
I was only trying to help.
Nothing you said made me think that you can't have a form at the parent level.
I always have something else to add (that's my cross to bear) but I'll try to remember not to with you.
I understand what you mean. You're trying to pass a trigger from the external save button to the "hidden" save button inside to trigger validation. That's a trick.
Specifically, if your button is on the Parent screen, you need to get the data, process the data, and save the data directly on the screen.
And importantly, the block is just a place to display the information. this is best practice, and you need use event to give data block back to screen.
Hope this helps!