Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Text field validation with a Twist

Avatar

Former Community Member
I have three text fields texta, textb and textc in which they need to validated upon submitting the document via a submit button. I need to validate the following:



When the user enters information into TextfieldA then TextfieldB and C dont need to be validated but if a user enters information into TextfieldB then TextfieldA and C dont need to be validated and so fourth. All three Text fields still need to be validated if the user has entered any information into any of them.



How would I go about solving this problem on the submit button or any other way?



Thanks
3 Replies

Avatar

Former Community Member
Since it sounds like you only need to perform the validations just before the form gets submitted, you can probably use what I call the "two button submit technique" (I'm going with a term here since it's used so often).



This consists of using two buttons: One regular button and one submit button (either email or HTTP). The submit button is made invisible and the Click event of the regular button (the "fake submit button") is used to perform the validations and, if all succeed, execute the invisible submit button's Click event, triggering the submission of the form.



To illustrate this concept, I've created a sample form with three text fields where at least one text field needs to be filled prior to submitting the form.



Stefan

Adobe Systems

Avatar

Former Community Member
FormBuilder@adobeforums.com wrote:

> Since it sounds like you only need to perform the validations just before the form gets submitted, you can probably use what I call the "two button submit technique" (I'm going with a term here since it's used so often).

>

> This consists of using two buttons: One regular button and one submit button (either email or HTTP). The submit button is made invisible and the Click event of the regular button (the "fake submit button") is used to perform the validations and, if all succeed, execute the invisible submit button's Click event, triggering the submission of the form.

>

> To illustrate this concept, I've created a sample form with three text fields where at least one text field needs to be filled prior to submitting the form.

>

> Stefan

> Adobe Systems



You can also manipulate the 'mandatory' property in script. For example, you could set all three

fields to required initially, and then you could put the following code on the 'exit' event of field A:

if (this.rawValue != null)

{

this.mandatory = "error";

this.parent.fieldB.mandatory = "disabled";

this.parent.fieldC.mandatory = "disabled";

}



This will make fieldB and fieldC optional once fieldA has been filled in. You would put similar

script on the other two fields.



The benefit of this over the two-button submit technique is that you will still get the automatic

validation and highlighting of required fields that is provided within Acrobat and Reader.



--

Justin Klei

Cardinal Solutions Group

www.cardinalsolutions.com

Avatar

Former Community Member
Thanks Stefan Your a Asset to Adobe Systems.



Thank you from the land downunder (Australia)