Expand my Community achievements bar.

AEM forms - check form validation status

Avatar

Level 3

Hello,

 

I am learning features available in the AEM forms. I am building a form that consist of multiple panels and I would like to show the submit button only if all required fields are valid.

 

I can see that there is an API that allows to validate form using `guideBridge.validate()` which will return true/false but this also changes the form (invalid fields are marked as invalid). Is there a function that can check if form is valid without actually changing form fields? I wonder how I could dynamically show/hide submit button based on the status of the for.

API: https://developer.adobe.com/experience-manager/reference-materials/6-5/forms/javascript-api/GuideBri...

5 Replies

Avatar

Employee Advisor

@bartek_887  Your understanding is correct if you call validate then the validation will run on the fields and the fields that fail the check will be highlighted. " check if the form is valid without actually changing form fields"- This doesn't fit the general use case, any fields that fail validation need to be highlighted before the next action can take place. 

Avatar

Level 3

In my use case I wanted to add a submit button that is:

1. Visible on the last panel of the form

2. Visible on the other panels only if the form is filled and can be actually submitted

This is just a demo scenario that I wanted to implement to learn more about this features. 

 

That's why I wonder whether there is a function that can return the information about the fields without changing the form status. For example if user just opened the form it's not valid (because all fields are empty) and in that case I would like to hide the submit button - but calling validate will highlight all of the fields which is not acceptable. 

 

As far as I understand the answer for my question is: no, at the moment there is no API that allows to check form validation status without actually validating the form which changes all invalid fiends.  

Avatar

Employee Advisor

@bartek_887 That's fairly doable. Let me send you a sample. so basically if all the fields are filled then only submit is shown.