How to prevent changing values in a field from onChange client script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2019 03:02 PM
I have a requirement to prevent changing values of certain field from onChange client script.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
if ( newValue === '' ) {
var ans = confirm("Confirmation message.");
if (ans == true){
g_form.setValue('comments', " ");
}
else if (ans == false){
// Need to prevent changing values here
return;
}
}
}
What are the possible ways that I can prevent changing values of the field based on condition?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2019 03:07 PM
You can always set it back to old value using oldValue variable defined in the onchange client script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2019 03:16 PM
oldValue will only hold the value which will be there in the field while loading the form. In this case, I cannot set the value to oldValue beacuse if I change value from valueA to valueB and again valueB to valueC without saving the form, oldValue will always hold valueA.
I need something that, if the value changed from valueA to valueB and again valueB to valueC, and if valueC is selected from choice the field value not supposed to be changed. i.e. the valueB will remain in that field.
Hope I could make you understand my concern.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2022 08:26 PM
Did you find any solution for this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2022 08:51 PM
Hi Abhrajyoti,
If you do not want the user to select a particular option you can use removeOption() method to achieve this. If the option is not available then user will not be able to select it.
So when user selects the value as B then in the Onchange client script you can check if the newValue == B then use removeOption() method to remove the option C to be selected