Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Text field required based on data entered in a previous field

saskiahope
Level 2
Level 2

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
Bibhu_Bikash_Na
Correct answer by
Level 9
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
dcidev
Level 8
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

saskiahope
Level 2
Level 2

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?

dcidev
Level 8
Level 8

if (!this.isNull){

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

TextField3.mandatory="error";

}

else

TextField3.mandatory="disabled";

Kyle

saskiahope
Level 2
Level 2

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";

Mandy_Wiesener
Level 5
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

saskiahope
Level 2
Level 2

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";

}

Mandy_Wiesener
Level 5
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

saskiahope
Level 2
Level 2

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";

Bibhu_Bikash_Na
Correct answer by
Level 9
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