Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Text field required based on data entered in a previous field

Avatar

Former Community Member

Good afternoon,

I'm trying to implement a requirement such that if data is entered in text field A then text field B is required. From the research I've done on the forum, I believe I need to use the change event. But the only related entries I've seen involve drop downs or radio buttons and I'm not sure how to translate that into whether or not data is entered into a text field. Thanks in advance!

1 Accepted Solution

Avatar

Correct answer by
Level 9

Hi,

Pobably a samll mistake you have made. It should be xfa.event.newText. Not xfa.eventnewText . If you see carefull you have missed the "dot/." between event and newText. Try it and see what happens next.

Thanks,

Bibhu.

View solution in original post

10 Replies

Avatar

Level 8

You can also put it in the exit event of your field A:

if (!this.isNull)
TextFieldB.mandatory="error";
else
TextFieldB.mandatory="disabled";

Kyle

Avatar

Former Community Member

Thanks, Kyle! Your way makes much more sense. I implemented it and now there is a red border around field B when field B is left blank but data is entered into field A. Can you please tell me how to implement a pop up so it's clear to the user that if there is data in field A that field B is required?

Avatar

Level 8

if (!this.isNull){

xfa.host.messageBox("You must fill out field B!");

TextField3.mandatory="error";

}

else

TextField3.mandatory="disabled";

Kyle

Avatar

Former Community Member

Thanks a lot! If instead of field A being a text box, I change it to a drop down and it is the option "Other" that requires a entry in Field B, would the code be as follows:

 

if (this.rawValue == "Other") {

xfa.host.messageBox("You must fill out field B!");

TextField3.mandatory="error";

}

else

TextField3.mandatory="disabled";

Avatar

Level 5

The right version have to be:

if (xfa.eventnewText == "Other")

{

     //OR app.alert("You must fill out field B!");

     //OR xfa.host.messageBox("You must fill out field B!", PLEASE READ", 1,0);

      xfa.host.messageBox("You must fill out field B!");

      TextField3.mandatory="error";

}else

{

      TextField3.mandatory="disabled";

}

Hope it's helpful,

Mandy

Avatar

Former Community Member

Thanks, Mandy. Should this be on the change event? I'm having trouble getting it to work for some reason. I'm pretty inexperienced so I'm sure I'm overlooking something trivial. This is what I put on the change event:

 

if (xfa.eventnewText == "Other")

{

//OR app.alert("You must fill out field B!");

 

//OR xfa.host.messageBox("You must fill out field B!", PLEASE READ", 1,0);

xfa.host.messageBox("You must fill out field B!");

other.mandatory =

"error";

}

else

{

other.mandatory =

"disabled";

}

Avatar

Level 5

Hi,


the LCD is case sensitiv.

Other is not the sam as other.

You have to write

Other.mandatory = "error";
Other.mandatory = "disabled";

NOT

other.mandatory = "error";

The change-event is right.

Helpful?

Mandy

Avatar

Former Community Member

Thank again, Mandy. I changed all instances of "Other" to all start with an uppercase "O" but I still can't get it to work! I'm not getting an error, but nothing happens. Thanks in advance!

 

if  (xfa.eventnewText == "Other")

{

//OR app.alert("You must fill out field B!");

//OR xfa.host.messageBox("You must fill out field B!", PLEASE READ", 1,0);

xfa.host.messageBox("You must fill out field B!");

Other.mandatory =

"error";

}

else

{

}

Other.mandatory = "disabled";

Avatar

Correct answer by
Level 9

Hi,

Pobably a samll mistake you have made. It should be xfa.event.newText. Not xfa.eventnewText . If you see carefull you have missed the "dot/." between event and newText. Try it and see what happens next.

Thanks,

Bibhu.