Expand my Community achievements bar.

How Do I Create Conditionally Required Check Boxes?

Avatar

Former Community Member

Hi there,

I am working in LiveCycle Designer ES3.  How do I make child check boxes conditionally required when a parent check box is checked?  I am able to get script to work to make a text box required when its corresponding check box is checked, but I can't get the same script to make child check boxes required if a parent check box is checked. 

The problem I'm running into is that I can't change the Value Type of a check box to "Recommended" which is how I was able to get this conditional requirement to work for text boxes using the following script on the Change event for the text box's corresponding check box.

if(this.rawValue =='1')

{

EXAMPLETEXTBOXNAME.mandatory = "error";

Gender.mandatory = "error";

Gender.border.edge.color.value = "225,0,0";

}

else{

EXAMPLETEXTBOXNAME.mandatory = "disabled";

Gender.mandatory = "disabled";

Gender.border.edge.color.value = "0,0,0";

}

Please see the picture below.  When the top (parent) check box is checked, the user should be required to check at least one of the (child) check boxes below it.  Please let me know how to do this.

conditionallyrequiredcheckboxes.JPG

 

Thank you.

6 Replies

Avatar

Level 10

If you don't mind getting your hands dirty with the scripting there's a series of posts on John Brinkman's old Formfeed blog with some custom validation script objects that let you do things like requiring at least one selection in a group, min/max selections, etc.

http://blogs.adobe.com/formfeed/2008/11/validation_patterns_part_1.html

http://blogs.adobe.com/formfeed/2008/11/validation_patterns_part_2.html

http://blogs.adobe.com/formfeed/2008/11/validation_patterns_part_3.html

The latest version of the script objects are in the sample files of the following post:

http://blogs.adobe.com/formfeed/2009/03/a_form_to_design_a_form.html

Avatar

Former Community Member

Thanks, Jono.  Unfortunately, I am not experienced enough with Javascript to put that information to good use.  The script I used in my post is borrowed from a post I found within the forum here. It was straightforward enough for a noob like me, but the links you provided are way above my head. 

Avatar

Level 2

Clinton,

I am not sure how you check for required, do they submit via button?

it will definitely be a challenge if they need to select at least one. so what I would normally do, is I have the code in each parent object which will open the child. I then use the submit button to check for required. here is what I would write.

keep in mind, what values you setup in your checkbox:

in the chebox parent:

if (this.rawValue == 1){

childbox1.access = "open"

childbox2.access = "open"

//do this for all your child checkboxes, make the default chld checkbox as readonly

//i actually would work with presense instead since I do not like the end user to see anything if there is no action involved.

}

if(this.rawValue == 0){

childbox1.access = "readOnly"

//do for all child checkboxes.

}

* you can add color if you want to make it looked required, similar to what you did above for the textbox.

in the submit button do this

if (parentcheckbox.rawValue == 1 && chilbox1 != 1 && childbox2 != 1 && childbox3 != 1 ....so forth){

     app.alert ("You have indicated blah blah, please select at least one blah blah.")

}

Avatar

Level 2

additionally, in the parent checkbox you may want to add

.rawValue = "" code. so if they first click the checkbox and then decide to uncheck, the child will need to be reset.

let me know if you have any questions or I can help further.

Avatar

Former Community Member

Thanks for the info, Randy.  What is the script for resetting the child box if the user first checks a box then later decides to uncheck it?  Would it be:

if(this.rawValue == ""){

childbox1.access = "readOnly"

}

Avatar

Level 2

Clinton,

close, but check how what the ravwalue will be when it is off or on. so i would do the following:

//if yes, then it opens the child

if (parentcheckbox.rawValue == 1){

     childbox1.access = "open"

     ...so forth

}

//if no, it will make the child readOnly and remove checks if they exist

if (parentcheckbox.rawValue == 0){

     childbox1.access = "readOnly"

     childbox1.rawValue = "0"

     so forth for each childbox

}

//you can also use a case switch, but since this is only 2 options, if statements work well.

//childbox should be readOnly by default

//all should be put into the change event.

//your required will be checked during submit or save button. see prior message.