client script is setting drop down options working perfectly BUT onload it is removing options again

dave_edgar
Mega Guru

So, I have set up a client script to remove options depending upon option set on a dependant field BUT after refreshing form the options selected are refreshing, the clearOptions function is running again

I'm sure this is simple but I can new to client scripts.

Here is my script, any advice is welcome.   BTW this is on a scoped application.:

function onChange(control, oldValue, newValue, isLoading) {

  if (newValue === 'In Store'){

  g_form.clearOptions('complaint_sub_category');

  g_form.setMandatory('complaint_sub_category',false);

  g_form.setVisible('complaint_sub_category',false);

  }

}

I suspect I need to state isLoading is false, i tried but obviously got it wrong

Thanks in advance

1 ACCEPTED SOLUTION

Chuck Tomasi
Tera Patron

If you want the onChange client script to NOT run on loading (as an onLoad script does) Add these lines just inside the function.



if (isLoading)


        return;



Can you help me understand why you want to clear all the options in the case of the In Store value? This shouldn't be necessary if you are hiding it anyway. Perhaps just use a g_form.setValue('fieldname', ''); to set it to empty instead.


View solution in original post

6 REPLIES 6

Chuck Tomasi
Tera Patron

If you want the onChange client script to NOT run on loading (as an onLoad script does) Add these lines just inside the function.



if (isLoading)


        return;



Can you help me understand why you want to clear all the options in the case of the In Store value? This shouldn't be necessary if you are hiding it anyway. Perhaps just use a g_form.setValue('fieldname', ''); to set it to empty instead.


top man



on a previous version i had:



if (isLoading)


{}


 


which did not work, so I removed it, so close yet so far.



Thanks ctomasi


Harish KM
Kilo Patron
Kilo Patron

can you put   clearOptions before if loop and check also put alerts and check.


Regards
Harish

Robbie
Kilo Patron
Kilo Patron

Hi Dave,


An onChange script also runs onLoad.


This can easily be resolved by adding the following 2 lines:



function onChange(control, oldValue, newValue, isLoading) {


  if (isLoading)


        return;


  if (newValue === 'In Store'){


  g_form.clearOptions('complaint_sub_category');


  g_form.setMandatory('complaint_sub_category',false);


  g_form.setVisible('complaint_sub_category',false);


  }


}



Thanks Robbie



Please mark helpful and/or correct by clicking on the post link (client script is setting drop down options working perfectly BUT onload it is removing options again ) to help close out open questions and aid others with the same or similar question.