Clear the Dependent Field Values if the reference Field is empty

Tahzeeb
Giga Expert

Hi All,

I have a reference field based on which other refrence field value is populated.

 

Not when the value in the reference field is removed(Field is empty), other dependent fields value should be cleared out.

 

I have written below code but its not working, please suggest

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if(newValue == '')
{


//clear the value of field below



g_form.clearValue('new_log');}

}

}

 

1 ACCEPTED SOLUTION

Allen Andreas
Administrator
Administrator

Hi,

If possible, it'd be nice to use a UI Policy instead for this, but...you can fix your script like so:

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if(newValue == '')
{


//clear the value of field below



g_form.clearValue('new_log');}

}

}

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

4 REPLIES 4

Allen Andreas
Administrator
Administrator

Hi,

If possible, it'd be nice to use a UI Policy instead for this, but...you can fix your script like so:

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if(newValue == '')
{


//clear the value of field below



g_form.clearValue('new_log');}

}

}

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Thankyou very much Allen, This worked.

 

Would it be possible to provide some idea on why this was not working before

Sure 🙂

You had these lines at the top of your script (which is there by default) on onChange client scripts:

if (isLoading || newValue == '') {
return;
}

So these lines mean if the client script is running on Load of the form...OR...if the client script is running because the new value for that field is empty/null...don't do anything else and exit, basically.

So you needed to remove the || newValue == '' from your script above because in this scenario you did want to do something if the field is set to empty/null.

Please mark this reply as Helpful if it was.

Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Thankyou for the details:)