Expand my Community achievements bar.

SOLVED

Mandatory Text Field / Dropdown List depending on RadioButton option

Avatar

Level 1

Hi,

I am working on a form with a set of radio buttons: individual or joint.

A dropdown list will become visible if user clicks joint. How can I set this dropdown list to be mandatory only when "joint" is clicked?

And also - what would be the scripting like if I want to set a text field to become mandatory depending on radio button clicked?

Thanks in advance!

1 Accepted Solution

Avatar

Correct answer by
Level 4

Hello,

You can write the following script in the click event of the radio button

to make the TextField or the DropDownList mandatory and visible when the radio button is clicked and

text field / dropdown not to be mandatory when it is hidden.

if (this.rawValue == 1)
    {
        TextField1.presence = "visible";
        DropDownList1.presence = "visible";
        TextField1.mandatory = "error";
        DropDownList1.mandatory = "error";
    }
else
    {
        TextField1.rawValue = null;
        DropDownList1.rawValue = null;
        TextField1.presence = "invisible";
        DropDownList1.presence = "invisible";
        TextField1.mandatory = "disabled";
        DropDownList1.mandatory = "disabled";
    }   

Thanks,

Debadas.

View solution in original post

4 Replies

Avatar

Level 7

Hi,

The answer is:

     DropDownList1.validate.nullTest = "error";

Works for any field, dropdown or radio button group.

Good luck,

Stephen

Avatar

Level 1

Thanks Stephen.

Perhaps I didn't stay it clear enough on my initial message - I don't want the text field / dropdown to be mandatory when it is hidden.

Is there way to set it to become mandatory only when it is visible upon the right click (in this case - "joint' is clicked)?

Cheers.

Avatar

Correct answer by
Level 4

Hello,

You can write the following script in the click event of the radio button

to make the TextField or the DropDownList mandatory and visible when the radio button is clicked and

text field / dropdown not to be mandatory when it is hidden.

if (this.rawValue == 1)
    {
        TextField1.presence = "visible";
        DropDownList1.presence = "visible";
        TextField1.mandatory = "error";
        DropDownList1.mandatory = "error";
    }
else
    {
        TextField1.rawValue = null;
        DropDownList1.rawValue = null;
        TextField1.presence = "invisible";
        DropDownList1.presence = "invisible";
        TextField1.mandatory = "disabled";
        DropDownList1.mandatory = "disabled";
    }   

Thanks,

Debadas.

Avatar

Level 7

Hi,

Sorry, I didn't consider that you needed the rest of the details for a complete script. I thought you were just looking for the method.

Good luck!

Stephen