- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2024 03:31 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2024 03:48 AM - edited 04-10-2024 03:58 AM
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).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2024 03:48 AM - edited 04-10-2024 03:58 AM
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).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2024 05:43 AM
Thanks for the solution I have created ui policy which is working fine.
Regards,
Venkatesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2024 03:58 AM
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