Clear a field value when non blank value in other field changes

Ajay37
Tera Contributor

Hi All,

 

I have two fields on the catalog form. One is of type choice and other is reference field. Now I need to clear values in each other field when a value in other field changes. But this should happen only when there is a value in a field and it changed to some other value. It shouldn't happen when blank value changed to some other value.

For suppose, on load of the form both choice field and reference field are empty.

Now when user selects a choice in choice field and he moves to fill a value in reference field. Initially reference field is empty on load and when user tries to fill in value, logically the value got changed and script is clearing the value in choice field. But this shouldn't happen in my case, the values should be cleared only when a non blank value got changed to some other non blank value. Please let me know if you need more information.

 

Thanks in Advance

9 REPLIES 9

This requires 2 on onChange client scripts, not onLoad clients scripts,
script 1 runs when field1 changes and updates field2, if field1 is not '' (newValue) and was not previously '' (oldValue)

script 2 runs when field2 changes and updates field1 using same logic.

Hi Tony,

 

On change itself gets triggered whenever the field value changes. We need to restrict it from getting triggered in specific scenarios as I mentioned in below comment.

 

Thanks

Ajay,

 

I think you need 2 onChange client scripts for these 2 scenarios that you have mentioned. Do the permutations based on the field changes.

Hi Omkar,

 

I want to restrict the On change script from getting triggered, when the value in field changed from null to not null. It should trigger only when value changed from not-null to not- null.

 

But by default on change script triggers, whenever there is change in the field.

 

Thanks

You can check something like oldValue != null || oldValue!=newValue somthing of that sort.