The CreatorCon Call for Content is officially open! Get started here.

when I select the none option in the field then another field also will be the same like "'--none--"

prasad24
Tera Contributor

I have taken two fields which are "City" and "Pin code". both the city and pin code fields already include "-- None --", and  want to set the pin code field to "-- None --" when "None" is selected in the city field, 

I  have written the client script for When the choice value is selected in the City field then adding the options Here Working properly (added options when i select the city choice))Here Working properly (added options when i select the city choice))Here i went back it means i select none, but it still showing pin code valueHere i went back it means i select none, but it still showing pin code valueon the Choices to the Pin code field.

 options are added to the "Pin code" field properly but,

when the 'none' option is selected it shouldn't clear the existing value.

it shows the existing value even though I select the "none" option in the "city" field.

 

Note :  on the Service Portal,


I tried the below code:

 

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

   if (newValue == 'Hyd') {
      g_form.clearOptions('u_pin_code');
      g_form.addOption('u_pin_code', '100001', '100001');
      g_form.addOption('u_pin_code', '100002', '100002');
      g_form.addOption('u_pin_code', '100003', '100003');
   } else if (newValue == 'Bangalore') {
      g_form.clearOptions('u_pin_code');
      g_form.addOption('u_pin_code', '200001', '200001');
      g_form.addOption('u_pin_code', '200002', '200002');
      g_form.addOption('u_pin_code', '200003', '200003');
   } else if (newValue == 'Chennai') {
      g_form.clearOptions('u_pin_code');
      g_form.addOption('u_pin_code', '300001', '300001');
      g_form.addOption('u_pin_code', '300002', '300002');
      g_form.addOption('u_pin_code', '300003', '300003');
   } else if (newValue == '-- None --') {
      g_form.setValue('u_pin_code', '-- None --');
   }
}



6 REPLIES 6

Harish KM
Kilo Patron
Kilo Patron

Hi @prasad24 you can do like this

if(newValue == '')

{

g_form.clearValue('variablename');

}

Regards
Harish

Yousaf
Giga Sage

Hi @prasad24 
I haven't tried it but can you please try this and let me know if this works

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

   if (newValue == 'Hyd') {
      g_form.clearOptions('u_pin_code');
      g_form.addOption('u_pin_code', '100001', '100001');
      g_form.addOption('u_pin_code', '100002', '100002');
      g_form.addOption('u_pin_code', '100003', '100003');
   } else if (newValue == 'Bangalore') {
      g_form.clearOptions('u_pin_code');
      g_form.addOption('u_pin_code', '200001', '200001');
      g_form.addOption('u_pin_code', '200002', '200002');
      g_form.addOption('u_pin_code', '200003', '200003');
   } else if (newValue == 'Chennai') {
      g_form.clearOptions('u_pin_code');
      g_form.addOption('u_pin_code', '300001', '300001');
      g_form.addOption('u_pin_code', '300002', '300002');
      g_form.addOption('u_pin_code', '300003', '300003');
   } else if (newValue == '') {
      g_form.setValue('u_pin_code', '');
   }
}

 

Mark Correct and Helpful if it helps.


***Mark Correct or Helpful if it helps.***

Hello,

 

Try using g_form.clearValue('u_pin_code');

 

Thanks

prasad24
Tera Contributor

Hi @Yousaf 
It's not working
I'm getting the same issue