onChange Client Script with --None--

kristenankeny
Tera Guru

We had some conflicts between Client Scripts and UI Policies, so are attempting to make our rules via Client Script. It is mostly working, except one thing. The field we are running the rules again is a choice field with --None-- as an option. There is an onLoad script that hides all of the fields dependent upon the choice in the "u_customer" field. Then we have an onChange running against u_customer. If you change the selection from --None-- to Producer or Consumer, the code runs correctly. However, when you change from Producer or Consumer back to --None--, the fields aren't hidden. We've tried the code (two versions) below:

Version 1:

if(g_form.getValue('u_customer') == 'producer'){

  g_form.setDisplay('u_producer_code',true);

  g_form.setDisplay('u_life',true);

  g_form.setDisplay('u_ltc',true);

  g_form.setDisplay('u_annuity',true);

  g_form.setDisplay('u_verified_date_of_birth',false);

  g_form.setValue('u_verified_date_of_birth',false);

  if(g_form.getValue('call_type') !== 'wrong_number' && g_form.getValue('call_type') !== 'hang_up'){

  g_form.setMandatory('u_producer_code',true);

  }

  }

  else if(g_form.getValue('u_customer') == 'consumer'){

  g_form.setDisplay('u_verified_date_of_birth',true);

  g_form.setMandatory('u_producer_code',false);

  g_form.setDisplay('u_producer_code',false);

  g_form.setDisplay('u_life',false);

  g_form.setDisplay('u_ltc',false);

  g_form.setDisplay('u_annuity',false);

  g_form.setValue('u_producer_code',null);

  g_form.setValue('u_annuity',false);

  g_form.setValue('u_life',false);

  g_form.setValue('u_ltc',false);

  }

else {

  g_form.setDisplay('u_verified_date_of_birth',false);

  g_form.setMandatory('u_producer_code',false);

  g_form.setDisplay('u_producer_code',false);

  g_form.setDisplay('u_life',false);

  g_form.setDisplay('u_ltc',false);

  g_form.setDisplay('u_annuity',false);

  }

Version 2:

if(g_form.getValue('u_customer') !== 'consumer' && g_form.getValue('u_customer') !== 'producer') {

  g_form.setDisplay('u_verified_date_of_birth',false);

  g_form.setMandatory('u_producer_code',false);

  g_form.setDisplay('u_producer_code',false);

  g_form.setDisplay('u_life',false);

  g_form.setDisplay('u_ltc',false);

  g_form.setDisplay('u_annuity',false);

  }

  else if(g_form.getValue('u_customer') == 'producer'){

  g_form.setDisplay('u_producer_code',true);

  g_form.setDisplay('u_life',true);

  g_form.setDisplay('u_ltc',true);

  g_form.setDisplay('u_annuity',true);

  g_form.setDisplay('u_verified_date_of_birth',false);

  g_form.setValue('u_verified_date_of_birth',false);

  if(g_form.getValue('call_type') !== 'wrong_number' && g_form.getValue('call_type') !== 'hang_up'){

  g_form.setMandatory('u_producer_code',true);

  }

  }

  else if(g_form.getValue('u_customer') == 'consumer'){

  g_form.setDisplay('u_verified_date_of_birth',true);

  g_form.setMandatory('u_producer_code',false);

  g_form.setDisplay('u_producer_code',false);

  g_form.setDisplay('u_life',false);

  g_form.setDisplay('u_ltc',false);

  g_form.setDisplay('u_annuity',false);

  g_form.setValue('u_producer_code',null);

  g_form.setValue('u_annuity',false);

  g_form.setValue('u_life',false);

  g_form.setValue('u_ltc',false);

  }

Neither of these triggers a hide of the fields when --None-- is selected after another option.

1 ACCEPTED SOLUTION

I think this is the line is not allowing it to trigger -



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


    if (isLoading || newValue === '') { //could you please remove this part newValue === '' and check


          return;


    }



    //Type appropriate comment here, and begin script below


   


}


View solution in original post

8 REPLIES 8

Thats cool. thanks for your feedback


Hi @ghsrikanth 

 

Worked like a charm, Thank you  so much. Could you please explain the logic behind this?

--none-- is the same as null basically. Try the condition if(g_form.getValue('u_customer')=='')


oh, and yes....what srikanth says is absolutely accurate, the newvalue=='' is dumping you out whenever you go back to none.