Checkbox Problem in Catalog Client Script

jeansky
Tera Contributor

Hello, I would like to ask why the select boxes don't show when I select the checkboxes. I don't know if this is possible in catalog client script. Any suggestion is appreciated. Thank you.

 

Here's my script:

 

function onChange(control, oldValue, newValue, isLoading) {

    g_form.setDisplay('checkbox1', false);
    g_form.setDisplay('checkbox2', false);
    g_form.setDisplay('checkbox3', false);
    g_form.setDisplay('selectbox1', false);
    g_form.setDisplay('selectbox2', false);
    g_form.setDisplay('selectbox3', false);

    var request_type = g_form.getValue('request_type');
    if (request_type == 'Account Creation') {
            g_form.setDisplay('checkbox1', true);
            g_form.setDisplay('checkbox2', true);
            g_form.setDisplay('checkbox3', true);

            var checkbox1 = g_form.getValue('checkbox1');
            var checkbox2 = g_form.getValue('checkbox2');
            var checkbox3 = g_form.getValue('checkbox2');

            if (checkbox1 == true) {
                g_form.setDisplay('selectbox1', true);
            }
            else if (checkbox2 == true) {
                g_form.setDisplay('selectbox2', true);
            }
            else if (checkbox3 == true) {
                g_form.setDisplay('selectbox3', true);
            }
            else {
                g_form.setDisplay('selectbox1', false);
                g_form.setDisplay('selectbox2', false);
                g_form.setDisplay('selectbox3', false);
            }
    }

    else if (request_type == 'Delete Account') {
            g_form.setDisplay('checkbox1', true);
            g_form.setDisplay('checkbox2', true);
            g_form.setDisplay('checkbox3', true);
    }
 
}

jeansky_1-1701355735680.png

 

jeansky_0-1701355687208.png

1 ACCEPTED SOLUTION

Based on my understanding of your code, I would suggest that within your new onChange client scripts on each Checkbox, you can have a condition like -

 

if(g_form.getValue('checkbox1')==true && g_form.getValue('request_type')=='Account Creation')

{

//show the select-box part

}

 

This way whenever RequestType if 'Delete Account' & even if CheckBox1 is true, you won't be showing SelectBoxes. Same logic you can put in all the other onChange client scripts as well.

 

Do mark this response as CORRECT / HELPFUL if you find it appropriate.

 

 

View solution in original post

8 REPLIES 8

jeansky
Tera Contributor

Thanks a lot. It worked. 😊 

My First Accepted Solution - Thanks @jeansky 😀

H S B
Giga Guru

My understanding is, you need to write a different onChange client script on each CheckBox1/2/3 if you want to show another field whenever these are checked / unchecked.

 

Currently you are trying to show everything onChange of 'Request_Type' field.

 

For more details, can you please explain, on which variable change, you want to show the selectBox variables? 

 

Do mark this answer as HELPFUL / CORRECT if it helps.

Sandeep Rajput
Tera Patron
Tera Patron

@jeansky As suggested by Elijah, you would need to define onChange scripts for your check boxes too. However, I recommend you to create UI Policies instead to hide/show the select boxes.