Expand my Community achievements bar.

SOLVED

Field mandatory if subform visible - not mandatory if subform hidden

Avatar

Former Community Member

Hi everybody

How can I make a field mandatory if the sub form containing the field is visible and not mandatory if the sub form is hidden?

Kirstine

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi Kirstine,

Just checked here and it works. You need to target the radio button exclusion group and not the individual radio buttons. For example, if the exclusion group was called "RadioButtonList", then:

RadioButtonList.mandatory = "error"; // would make the radio buttons required

and

RadioButtonList.mandatory = "disabled"; // would make the radio buttons optional

Hope that helps,

Niall

View solution in original post

5 Replies

Avatar

Level 10

Hi Kirstine,

I have an example here:

http://www.assuredynamics.com/index.php/category/portfolio/changing-the-mandatory-property/

This changes the mandatory property from 'error' (field is mandatory/required) to 'disabled' (field is optional).

Please note that you should make the field visible first before setting the mandatory property. Similarly when hiding the field, set the mandatory property back to disabled first.

Hope that helps,

Niall

Avatar

Former Community Member

Hi Niall

Thanks for your quick answer. Now I'm half way there.

As I read it, the script you use set all fields to mandatory. I need to be able to set some fields in the sub form to mandatory and some fields should still be optional.

I am not quite sure of that you mean when you say: set mandatory property, before you change the presence of the object. Can you explain that a bit more?

It is the choice in a drop-down list that makes the sub form become visible. I have placed a script on docReady to make one sub form visible and hide the rest.

Kirstine

Avatar

Level 10

Hi Kristine,

Yes the script is in the exit event of the dropdown. You could have script in a different type of object/different event, it just depends on what is triggering the show/hide of the objects. The docReady event should work.

The script is not making all of the fields mandatory. It targets two textfields individually (TextField1 and TextField2). For example, vMandatory is set to "error" or "disabled" depending on the item selected in the dropdown. "sometimesHidden" is the name of the subform:

sometimesHidden.TextField1.mandatory = vMandatory; // set the mandatory property first


sometimesHidden.TextField2.mandatory = vMandatory;


sometimesHidden.presence = this.getDisplayItem(vChoice); // then set the presence property

In relation to the sequence, I believe it is better to set the mandatory property first and then the presence property (as above).

Hope that helps,

Niall

Avatar

Former Community Member

Hi Niall

It works fine now on text fields. But I have a group of radio buttons that I want to make mandatory as well, and the script doesn't seem to work on that part.

Kirstine

Avatar

Correct answer by
Level 10

Hi Kirstine,

Just checked here and it works. You need to target the radio button exclusion group and not the individual radio buttons. For example, if the exclusion group was called "RadioButtonList", then:

RadioButtonList.mandatory = "error"; // would make the radio buttons required

and

RadioButtonList.mandatory = "disabled"; // would make the radio buttons optional

Hope that helps,

Niall