Expand my Community achievements bar.

Validate mandatory fields prior to submit

Avatar

Level 9
Hi



If you have a submit/email button on a form, when the user clicks it, it will check that all the mandatory fields have been entered. If any are missing, it will not let you submit.



However, if you do your submit using Javascript, then no checks are performed.



The documentation implies that this can be done. From page 42 of the Javascript reference:



] "The client may choose to prevent the form from being committed if any part of the form is invalid. For example, a client may choose to prevent the submission or saving of a form until it is considered valid."



Does anyone know how do you do this?



I've scoured the documentation and the newsgroups, and can find no way of doing this (other than laboriously writing code to check each field individually, which is a huge maintenance headache).



Many thanks,

Howard
2 Replies

Avatar

Former Community Member
Rather than doing a "submit using JavaScript" what you could do is trigger the click event of a hidden submit button. That way it should do the standard validation as if the user had actually clicked on the submit button.



Button.execEvent("click");



Chris



Adobe Enterprise Developer Support

Avatar

Former Community Member
Hi,



I am new to form designer and had the following questions:



1. Assuming that I perform validation checks on my form fields on the click event of Submit button, how do I set the focus to a form field if validation on that field fails? I am using javascript



2. I am using app.alert() to display message to the user if the field is invalid. This works fine. The user sees a pop up window with the message and the form does not get posted. Once the user rectifies the error and clicks submit, the form does not get posted. Do you have a sample code that you can post?



Thanks