Expand my Community achievements bar.

User checks YES checkbox, how do I require user to comment then?

Avatar

Former Community Member
I have created a form with a yes checkbox and a no checkbox and then a text field; if user clicks YES checkbox I want them to then be required to provide a comment; how do I do that?



thanks for any help.



P.S. I am new to javascript and/or formcalc.
2 Replies

Avatar

Former Community Member
GMS,



Designers often choose between applying rules at the time individual objects are filled versus applying rules to all objects when a form is submitted or saved. The following describes the first option.



Radio buttons are nice option instead of check boxes. They can be made to look like check boxes and you don't have to manage the alternative response (un-check).



Create a radio button list, called 'answer', defined as an exclusion group with the radio buttons 'yes' and 'no'. Define the item bindings on 'answer' as 1 - yes and 0 - no. Additionally, create a text field called 'comments'.



Given the form root is called 'form1' and a subform called 'subform1', the following events could be added to help enforce comments as a required field.



// form1.subform1.answer::click - (JavaScript, client)



if (form1.subform1.answer.rawValue == "1") {

if (form1.subform1.comments.editValue.length == 0 && form1.subform1.comments.formattedValue.length == 0) {

xfa.host.setFocus("form1.subform1.comments");

}

}

else {

form1.subform1.comments.rawValue = "";

}



// form1.subform1.comments::exit - (JavaScript, client)



if (form1.subform1.comments.editValue.length == 0 && form1.subform1.comments.formattedValue.length == 0) {

if (form1.subform1.answer.rawValue == "1") {

xfa.host.messageBox("Comments are required.");

xfa.host.setFocus("form1.subform1.comments");

}

}



If this makes no sense, send an email to stwalker.adobe@gmail.com and I can forward the form.



Steve

Avatar

Former Community Member
http://www.adobeforums.com/webx/.59b7ca75

Check out Nialls solution. He even told me how to make a red boarder to show the user that this field got required.