The CreatorCon Call for Content is officially open! Get started here.

how to set text field editable for one choice out of six choices in select box in catalog form.

t venkatesh1
Tera Contributor

Hi all,

i have two variables 1.select box , 2.single line text

 select box having six choices (ex; test1,test2,test3,test4,test5,others) based on the choice single line text field will auto populate with some data it is set to read-only, but if user selects "others " the single line text field set to be editable.  

 

please suggest client script for this when only user selected "others" single line text is editable, else it is read-only for remaining choices.

find the below screenshot it is read-only for all choices but i want editable when user select others choice option.

regards,

venkatesh t

1 ACCEPTED SOLUTION

Nick Parsons
Mega Sage

Don't use a client script for this (keep your form low-code where possible), instead, use a UI policy.

For the UI Policy, on the When To Apply tab you can set the following:

- Condition: select_box_variable IS others

- Reverse if false: Checked (true)

- Onload: Checked (true)

Then on the related list, create a new UI Policy Action:

- Field name: single_line_text_variable

- Read only: Unchecked (false)

 

If you must use a client-script, create an onChange client for the select box variable (set the UI Type to the appropriate value based on where your form is being used, otherwise it won't run).  In the script, you can control the read-only state of the single-line text variable with g_form.setReadOnly():

 

function onChange(control, oldValue, newValue, isLoading) {
   var isTextEditable = newValue == "others";
   g_form.setReadOnly("single_line_text_variable", isTextEditable);
}

 

 

Note that in both solutions, if the text field is mandatory, it cannot be made read-only (which doesn't seem to be the case in your example).

View solution in original post

3 REPLIES 3

Nick Parsons
Mega Sage

Don't use a client script for this (keep your form low-code where possible), instead, use a UI policy.

For the UI Policy, on the When To Apply tab you can set the following:

- Condition: select_box_variable IS others

- Reverse if false: Checked (true)

- Onload: Checked (true)

Then on the related list, create a new UI Policy Action:

- Field name: single_line_text_variable

- Read only: Unchecked (false)

 

If you must use a client-script, create an onChange client for the select box variable (set the UI Type to the appropriate value based on where your form is being used, otherwise it won't run).  In the script, you can control the read-only state of the single-line text variable with g_form.setReadOnly():

 

function onChange(control, oldValue, newValue, isLoading) {
   var isTextEditable = newValue == "others";
   g_form.setReadOnly("single_line_text_variable", isTextEditable);
}

 

 

Note that in both solutions, if the text field is mandatory, it cannot be made read-only (which doesn't seem to be the case in your example).

Thanks for the solution I have created ui policy which is working fine. 

Regards, 

Venkatesh 

Maddysunil
Kilo Sage

@t venkatesh1 

On change client script:

 

 var selectBoxValue = g_form.getValue('select_box_variable_name'); // Replace 'select_box_variable_name' with the actual variable name of the select box
    
    if (selectBoxValue == 'others') {
        // If user selects "others", make the single line text field editable
        g_form.setReadonly('single_line_text_variable_name', false); // Replace 'single_line_text_variable_name' with the actual variable name of the single line text field
    } else {
        // For other choices, make the single line text field read-only
        g_form.setReadonly('single_line_text_variable_name', true); // Replace 'single_line_text_variable_name' with the actual variable name of the single line text field
    }
}

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks