addoption removeoption

levino
Giga Guru

Hi Experts

 

i have a issue please

options =  is the onchange variable

 

the first if statements evaluates as expected, the second else if does nothing, that is it does not display the field altogether

Thanks

Levino

 

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
      return;
   }
    
    g_form.clearOptions('options');
    var hours = g_form.getValue('contracted_hours');

    if (hours <= 29) {
        g_form.addOption('options', '', 'None');
        g_form.addOption('options', 'Self-paced learning with support from team & Capability', 'Self-paced learning with support from team & Capability (Ideal for part timers or a return advisor)');
        g_form.addOption('options', 'Full time Facilitated Onboarding (Committed for 40 hours a week for 5 weeks)', 'Full time Facilitated Onboarding (Committed for 40 hours a week for 5 weeks)');
    } else if(hours >= 30) {
 
        g_form.removeOption('options', 'Self-paced learning with support from team & Capability');
    }
}

//Type appropriate comment here, and begin script below

 

1 ACCEPTED SOLUTION

I see it functioning correctly though.

 

sonamtiwari_0-1707808008540.png

 

 

Do you have any UI policy or script running to hide the visibility of the field on this item?

 

 

Consider indicating the response as helpful and marking it as correct if it meets your needs.

View solution in original post

4 REPLIES 4

Sonam_Tiwari
Kilo Sage

Try this

 

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


     var hours = g_form.getValue('contracted_hours');

     if (newValue <= 29) {
         g_form.addOption('options', '', 'None');
         g_form.addOption('options', 'Self-paced learning with support from team & Capability', 'Self-paced learning with support from team & Capability (Ideal for part timers or a return advisor)');
         g_form.addOption('options', 'Full time Facilitated Onboarding (Committed for 40 hours a week for 5 weeks)', 'Full time Facilitated Onboarding (Committed for 40 hours a week for 5 weeks)');
     } else if (newValue >= 30) {
         alert('test')
         g_form.removeOption('options', 'Self-paced learning with support from team & Capability');
     }
 }

 //Type appropriate comment here, and begin script below

 

 

Consider indicating the response as helpful and marking it as correct if it meets your needs.

hi

i have tried , the second if does evaluate that is i get the test alert, but the field does not get displayed

Thanks

I see it functioning correctly though.

 

sonamtiwari_0-1707808008540.png

 

 

Do you have any UI policy or script running to hide the visibility of the field on this item?

 

 

Consider indicating the response as helpful and marking it as correct if it meets your needs.

dhanu3
Kilo Sage

@levino 

You are using client script to populate options. If it goes inside if loop then you are adding options but in else if you are removing option which is not available in variable choice list.

In else part you don't want any choice value? If this is so then it will show empty field only.

 

 

Please mark this comment as Correct Answer/Helpful if it helped you.

 

Regards,

Dhanu