Expand my Community achievements bar.

SOLVED

Required field in "hidden" subform

Avatar

Level 7

I have a set of 3 radio buttons. If #1 is selected then a subform with one text field is displayed. When displayed that field is required. All of that works fine. What doesn't work is if the user selects #1 then decides to select #2 instead, the subform correctly is "hidden" but the field is still seen as required. I'm not sure how to fix this. Here's the script:

//Create a variable to hold the document object

var v1 = form1.page3.accessApps.TextField11.rawValue;

//accessApps

if

((v1 == "") || (v1 == null) )

{

xfa.host.messageBox( "Please list the applications the associate should have access to" );

xfa.host.setFocus("form1.page3.accessApps.TextField11");

}

1 Accepted Solution

Avatar

Correct answer by
Level 10

You would just add the line to the script you are using to show/hide the subform or field.

if (x)
{
     FieldName.presence = "visible";
     FieldName.mandatory = "error";
}

View solution in original post

6 Replies

Avatar

Level 10

You can turn the required setting on and off with the following:

FieldName.mandatory = "error"; //mandatory
FieldName.mandatory = "disabled"; //not mandatory

Avatar

Level 7

Where would these go in the script(s) and on what event?

Thanks,

Margaret Dawn

Avatar

Correct answer by
Level 10

You would just add the line to the script you are using to show/hide the subform or field.

if (x)
{
     FieldName.presence = "visible";
     FieldName.mandatory = "error";
}

Avatar

Level 7

Here's how I inserted the lines in my script:

if

(this.rawValue == 1)

{

accessApps.presence

= "visible";

xfa.host.setFocus("form1.page4.accessApps.TextField11");

form1.page4.accessApps.TextField11.mandatory

= "error"; //mandatory

}

else

{

accessApps.presence

= "hidden";

form1.page4.accessApps.TextField11.mandatory

= "disabled"; //not mandatory

}

but it's not working.

Avatar

Level 10

Hi,

I would recommend that you place the mandatory line of script BEFORE the presence line. See here: http://assure.ly/hxHupW.

Niall