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.

Conditional Mandatory Fields

Avatar

Former Community Member
Hi,



Im looking for help on this one... How can I make a text field mandatory if someone ticks a check box or completes another field?
10 Replies

Avatar

Former Community Member
if ("checked") then

form.textField.validate.nullTest="error"

endif



Or onchange event of the second TextField put this:

form.textField.validate.nullTest="error"



Best regards

Avatar

Former Community Member
Hi Paul,



Thanks for that, I was wondering if this is the sort of thing I need to use but Im new to LiveCycle and I dont know where to actually put this code. Do I put it in the xml view or what? Im not sure?



Thanks again for your help..



Ross

Avatar

Former Community Member
In LC Designer there is script view with differnt sort of events. Yiu can put those scripts to change or click event.

Avatar

Former Community Member
Hi Paul., sorry, I remember seeing this field now. This is what Ive got in the field now:

form1.#subform[0].Taxi::preSubmit:form - (FormCalc, client)



if ("checked") then

form.Mobile.validate.nullTest="error"

form.Pickup-1.validate.nullTest="error"

form.Dropoff-1.validate.nullTest="error"

form.Collect-Date-1.validate.nullTest="error"

form.Collect-Time-1.validate.nullTest="error"

endif



Ive tried this but the form doesnt do what I want. I need the above fields to be mandatory if the 'taxi' box is ticked.



Any ideas?



Thanks



Ross

Avatar

Former Community Member
if ("checked") then - it was logical expression.

Code expression is:



if (taxi.rawValue==1) then

form.Mobile.validate.nullTest="error"

form.Pickup-1.validate.nullTest="error"

form.Dropoff-1.validate.nullTest="error"

form.Collect-Date-1.validate.nullTest="error"

form.Collect-Time-1.validate.nullTest="error"

endif

Avatar

Former Community Member
Hi Paul,



Thanks again for your help, it mates sense now but I think Im sticking on a couple of things, this is whats in the script box now when you highlight the checkbox:



form1.#subform[0].Taxi::preSubmit:form - (JavaScript, client)

if (taxi.rawValue==1) then

form.Mobile.validate.nullTest="error"

form.Pickup-1.validate.nullTest="error"

form.Dropoff-1.validate.nullTest="error"

form.Collect-Date-1.validate.nullTest="error"

form.Collect-Time-1.validate.nullTest="error"

endif



What im stuck on is:

1) which point do i want this script? ie: in the 'show' box, I currently have selected 'presumbit*' which is the section where the code is now.

2) What langauage do I use? when I tried formcalc i got an error, it seems to be happier with javascript



Sorry to be a pain.



Ross

Avatar

Former Community Member
1) You wanted to have validation script when checkbox is checked.

2) script written in formcalc

Avatar

Level 2
Hello,



I have a similar situation. I have been able to make a certain field mandatory when a particular box is checked. My problem is that I do not know how to make it optional if the user changes their mind and unchecks the box. Is there a way to make this happen? Thank you in advance for any help.



Jenn D.

Avatar

Former Community Member
Just change it from nulltest="error" to nulltest=""

Avatar

Level 2
Paul,



Thank you!!! It works just like I want it to now!



Jenn D.