How to prevent changing values in a field from onChange client script?

Abhrajyoti Kan1
Tera Contributor

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?

6 REPLIES 6

Sathish
Tera Contributor

Hi,

I have a similar issue, I want to prevent changing the variable value to another if the condition is failed. Unable to use oldValue on onchange client script to set

Hi Sathish,

 

Explore g_form.addOption() and g_form.removeOption methods. It will resolve your issue. Based on conditions you can add or remove options from a field so user will have only those options to select which you want them to select.

 

Please mark my answer as correct, if it helped you resolve your query