Expand my Community achievements bar.

Fields only "required" when visible

Avatar

Level 1

Hi,

I am trying to create a form that has radio buttons "yes" and "no".  I have it set so that a comments box (that is hidden and excluded from layout) becomes visible when the "no" button is clicked and remains hidden or re-hidden (not a real word) when the "yes" button is clicked.

My difficulty is that I would like the comments box to be required only when it is visible.

Can anyone help with the scripting?

6 Replies

Avatar

Former Community Member

Hi,

Please try this code.

Firstly, you must hide the "CommentsBox"

/////////// click event of "Yes" radio button.////////////////

CommentsBox.presence = "visible"

CommentsBox.validate.nullTest = "error";

/////////// click event of "No" radio button.////////////////

CommentsBox.rawValue = ""

CommentsBox.validate.nullTest = "disabled"

CommentsBox.presence = "hidden"

I hope this help,

S,Candy

Avatar

Level 1

Hi Candy,

Thank you so much for your prompt response.  I have tried this. However if the user clicks "no" and then changes their mind and clicks "yes" the Comments box does not disappear.

I have tried this in the Yes:

xfa.form.form1.Inspection.Comments2.presence = "hidden";

var NumOfComments = xfa.form.form1.Inspection.Comments2.count;

//If there is an instance of the subform, remove it. There can only be 1 or 0 instances of the subform

if (NumOfComments == 1) {

xfa.form.form1.Inspection._Comments2.removeInstance(0);

}

xfa.form.form1.Inspection.Comments2.presence.validate.nullTest = "disabled"

And this in the No:

xfa.form.form1.Inspection.Comments2.presence = "visible";

var NumOfComments = xfa.form.form1.Inspection.Comments2.count;

//if the subform is not there (e.g. user already clicked yes), then add it back to the form

if (NumOfComments == 0) {

  xfa.form.form1.Inspection._Comments2.addInstance(1);

}

//make the subform visible

xfa. form.form1.Inspection.Comments2.presence = "visible";

xfa. form.form1.Inspection.Comments2.validate.nullTest = "error";

This causes the Comments box to disappear, but it does not fix the validation error.  It is still requiring the comments box at print.  Should I be adding script to validation or preprint?

I am new at this scripting thing and it has taken me so many hours just to get to where I am. My is an inspection checklist with 40 fields. I am so frustrated, any help you could provide would be much appreciated.

TBurg

Avatar

Level 10

Hi,

This is a major reason why I don't like Adobe validation system... there's always a leak somewhere.

You could be using my own method of validation..     Validation / Reset Functions, easy to manipulate and to change Forms!!!!

Or all what you need to do is the following

txtRequired.mandatory = "disabled"     //No warnings

txtRequired.mandatory = "warning"     //Warns the user that the field is null

txtRequired.mandatory = "error"          //Prompt user to error message because the field is null

Avatar

Level 1

Hi,

I looked at your form from one of the other posts.  Unfortunately, because I am so new at this I am unable to translate the functionality unless it is specific to my scenario.  I need to prevent printing only if the visible required fields are not complete.

Could I send you my form.  I am working on one with just two lines...just to get the functionality working before adding more.

Avatar

Level 10

Hi,

sorry I misunderstood what you were trying to do...

if you want to hide an object from printing when the required field is null you can simply add a statement in the prePrint and postPrint event of the objects...

Avatar

Level 1

Hi,

I actually managed to go back to S, Candy's answer and get it to work. 

My form is going really well.

I have now added a few repeating subforms, they have radio buttons that are scripted to cause comments boxes to be visible/required, just like the above example.  What is happening though is that the radio buttons in forms that have been added are controlling the comments box in the initial form.

Is there a way to script it so that the radio buttons will control the correct comments boxes?

TBurg