Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session

Mandatory field after check-box selection

Avatar

Level 1

While testing, I am experiencing an exception behaviour oddity on a runtime mandatory setting of a text field depending on which check-box a user selects...

I have two mutually-exclusive check-boxes, House and Appartment, plus a text-field named Floor.

If the user selects House, then I disable the mandatory and visibility settings of the Floor field. The opposite if the user selects Appartment...I want them to enter a Floor value in that case.

The scripts against a Click Event on the House and Appartment check-boxes, are as follows:

House:

this.resolveNode("Floor").rawValue = null;

this.resolveNode("Floor").mandatory = "disabled";

this.resolveNode("Floor").presence = "invisible";

Appartment:

this.resolveNode("Floor").presence = "visible";

this.resolveNode("Floor").mandatory = "error";

xfa.host.messageBox("Please enter the floor number on which the appartment is located", "Floor", 3);

When I test the form it's fine, except when trying the scenario where a user selects Appartment and then selects House, instead. Two messages are displayed...the first as in the code above (which is intended), followed by a mandatory field ERROR message saying the "Floor cannot be blank" before the user has had a chance to enter a value into the Floor text-field.

I would expect the ERROR message to appear if the form is submitted without a value being entered in Floor, but not BEFORE the user has an opportunity to do so.

How can this second message be prevented from appearing at this point ?

Whilst this may seem trivial in this simple example, I will have similar more complex rules to provide for in my development.

Any ideas would be appreciated. Thank-you

Guy

2 Replies

Avatar

Level 7

Your scripts are running whether the boxes are checked or not, so you just need to put in an if statement so your script will only run if the checkbox has a value of 1 (checked).

Avatar

Level 1

Thank-you whyisthisme. However, the problem remained after testing the value using an if statement. as suggested.

My code is now against the Change Event on the radio-group (rather than the check-box itself), as follows:-

Floor.mandatory = (House.rawValue == 1) ?  "disabled" : "error";

Floor.presence = (House.rawValue == 1) ?  "invisible" : "visible";

Floor.rawValue = null;

This works the same as described before, with the Floor field being highlighted and a Mandatory Error message appearing, BEFORE the user has had a chance to enter a value in Floor.

Any other ideas would be welcome.