Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Checkbox ticked issue

Avatar

Level 2

Hi,

I have 1 text field and 3 check box in my form. Depending on text typed in text field different checkbox will be ticked. I am using below code on exit event of text field. When I use this code all 3 checkbox could be ticked at a time. I am trying that only one check box will be ticked at time (something like radio button, only one can be ticked at time). I am trying to avoid radio button because once it is ticked, anyone of the group will remain as ticked.

switch(TextField1.rawValue){

    case "Address1":

        CheckBox1.rawValue = "1";

        break;

    case "Address2":

        CheckBox2.rawValue = "1";

        break;

    case "Address3":

        CheckBox3.rawValue = "1";

        break;

}

I also tried below code on exit event of text field but no checkbox is being ticked.

if (TextField2.rawValue == "Address1" || TextField2.rawValue == "Address2" || TextField2.rawValue == "Address3" || TextField2.rawValue == "Address4"){CheckBox1.rawValue = "1"}

else if (TextField2.rawValue == "Text1" || TextField2.rawValue == "Text2" || TextField2.rawValue == "Text3" || TextField2.rawValue == "Text4"){CheckBox2.rawValue = "1"}

else if (TextField2.rawValue == "Item1" || TextField2.rawValue == "Item2" || TextField2.rawValue == "Item3" || TextField2.rawValue == "Item4"){CheckBox3.rawValue = "1"}

else (TextField2.rawValue == "") {CheckBox1.rawValue = "0" && CheckBox2.rawValue = "0" && CheckBox3.rawValue = "0"}

Any idea how can I move forward, pls

Rgds

1 Accepted Solution

Avatar

Correct answer by
Level 7

Hi,

Put the code in the default. Anything that isnt exactly written as Address1, Address2 or Address3 will execute the default case.

default: //this is what will happen if none of the case statements apply, it can be left blank.

        CheckBox1.rawValue = "0";

        CheckBox2.rawValue = "0";

        CheckBox3.rawValue = "0";

        break;

View solution in original post

5 Replies

Avatar

Level 7

Switch will work fine. You are missing a default case as well at the bottom, this can be blank.

I quite often use checkboxes as radio buttons, you just need to turn off the boxes you dont want and turn on what you do for all of them in each case statement eg:

switch(TextField1.rawValue){

    case "Address1":

        CheckBox1.rawValue = "1";

        CheckBox2.rawValue = "0";

        CheckBox3.rawValue = "0";

        break;

    case "Address2":

        CheckBox1.rawValue = "0";

        CheckBox2.rawValue = "1";

        CheckBox3.rawValue = "0";

        break;

    case "Address3":

        CheckBox1.rawValue = "0";

        CheckBox2.rawValue = "0";

        CheckBox3.rawValue = "1";

        break;

    default: //this is what will happen if none of the case statements apply, it can be left blank.

        break;

}

Avatar

Level 2

Hi MinusZero

Thanks for the help.

Alternative selection of checkbox is working. But last checkbox remain ticked if I remove text from text box. I tried with below code but result is same.

    case "":

        CheckBox1.rawValue = "0";

        CheckBox2.rawValue = "0";

        CheckBox3.rawValue = "0";

Thanks

Avatar

Correct answer by
Level 7

Hi,

Put the code in the default. Anything that isnt exactly written as Address1, Address2 or Address3 will execute the default case.

default: //this is what will happen if none of the case statements apply, it can be left blank.

        CheckBox1.rawValue = "0";

        CheckBox2.rawValue = "0";

        CheckBox3.rawValue = "0";

        break;