Expand my Community achievements bar.

SOLVED

Field visible depending on a radio button choice

Avatar

Former Community Member

Hello to all,

I have this form where I have a radio button group Yes/No. I would like a numeric field to appear only when users click Yes. When the form opens or if users do not set it at Yes (No is default) the field must not appear.

Then there is a min and max limit attached to this field, which should only kick in when the field appears (limits should not be applied when the field is hidden).

My questions are:

Where should I put the visible/hidden condition ? On the radio button group subform or on each Yes/No condition ? I've tried both so far, but it hasn't worked.

The script I have tried is as follows (on event exit of the radio button group):

if (this.rawValue == 2) {

...RightDetection.ChoixYesNo.DetectionDelay.presence = "visible"

}

else (this.rawValue == 1) {

...RightDetection.ChoixYesNo.DetectionDelay.presence = "hidden"

}

The min/max limit used to work before, but since I've started toying with this field, I now have an error message on the first parenthesis. Could anyone tell me why ?

The limit script is as follows:

if (this.rawValue < 1)

{

    xfa.host.messageBox("Specify at least 1 in this field","Warning",1,0);

    xfa.host.setFocus(this);

}

if (this.rawValue > 365)

{

    xfa.host.messageBox("Specify at most 365 in this field","Warning",1,0);

    xfa.host.setFocus(this);

}

Thanks a lot in advance for your help.

1 Accepted Solution

Avatar

Correct answer by
Level 8

Why not just set the type of field to User Entered - Required

View solution in original post

3 Replies

Avatar

Level 10

Hi,

the setFocus() function expects a somExpression to a field.

So the syntax should look like:

if (this.rawValue < 1) {

    xfa.host.messageBox("Specify at least 1 in this field", "Warning", 1, 0);

    xfa.host.setFocus(this.somExpression);

}

if (this.rawValue > 365) {

    xfa.host.messageBox("Specify at most 365 in this field", "Warning", 1, 0);

    xfa.host.setFocus(this.somExpression);

}

The other script also needs a little fix.

When using an else, you don't need declare an expression, because "else" covers all other result different to the "if" you already declared before.

Also, there are no leading dots allowed in a somExpression.

Change your script into:

if (this.rawValue == 2) {

    RightDetection.ChoixYesNo.DetectionDelay.presence = "visible";

} else {

    RightDetection.ChoixYesNo.DetectionDelay.presence = "hidden";

}

Hope this helps.

Avatar

Former Community Member

Hello again,

I would like to add a condition to my field, which is that there should always be a value in this field, this field cannot remain empty. So I've tried the following:

if (this.isNull = 1) {

    xfa.host.messageBox("Specify a value from 1 to 365 in this field", "Warning", 1, 0);

    xfa.host.setFocus(this.somExpression);

}

if (this.rawValue < 1) {

    xfa.host.messageBox("Specify at least 1 in this field", "Warning", 1, 0);

    xfa.host.setFocus(this.somExpression);

}

if (this.rawValue > 365) {

    xfa.host.messageBox("Specify at most 365 in this field", "Warning", 1, 0);

    xfa.host.setFocus(this.somExpression);

}

But it doesn't work. The error message "Specify a value from 1 to 365 in this field" always appear, whatever the value entered in the field. I don't understand why.

Some help please ?

Avatar

Correct answer by
Level 8

Why not just set the type of field to User Entered - Required