Option "-- None --" is not appearing onChange

mkdj12
Giga Contributor

I'm using this onChange script to toggle what options are accessible from this select box variable. But for some reason the only option that doesn't appear is "-- None --". The field always selects the first option by default which is breaking other logic within the form. I've attempted to check the option on the variable to "include none" but that hasn't worked either. 

 

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

    if (isLoading || newValue == '') {
       return;
    }
    var topic = g_form.getValue('topic_of_request');
    if (topic == "brand_storytelling") {
        g_form.clearOptions('category');
        g_form.addOption('category', 'none', '-- None --');
        g_form.addOption('category', 'campaign', 'Campaign');
        g_form.addOption('category', 'menu', 'Menu');
        g_form.addOption('category', 'customer_comment', 'Customer Comment');

    } else if (topic == "issues_management") {
        g_form.clearOptions('category');
        g_form.addOption('category', '', '-- None --');
        g_form.addOption('category', 'disaster_crisis', 'Disaster/Crisis');
        g_form.addOption('category', 'food_safety', 'Food Safety');
        g_form.addOption('category', 'supply_chain', 'Supply Chain');
        g_form.addOption('category', 'diversity_inclusion', 'Diversity & Inclusion');
        g_form.addOption('category', 'political_social_cause', 'Political or Social Cause');
    } else {
        g_form.clearOptions('category');
    }
}

 

10 REPLIES 10

"make sure that the value fir '--None--' is '' (blank) and not 'none'"
This was a nice trick mate. Helped me in one of the requirements 🙂

Allen Andreas
Administrator
Administrator

Hi,

I'm curious if none is actually there, but since you aren't assigning an index to your addOption...it's showing out of order. I'd recommend adding indexes so that you control the order they show in, example:

g_form.clearOptions('category');
        g_form.addOption('category', '', '-- None --', 1);
        g_form.addOption('category', 'disaster_crisis', 'Disaster/Crisis', 2);
        g_form.addOption('category', 'food_safety', 'Food Safety', 3);
        g_form.addOption('category', 'supply_chain', 'Supply Chain', 4);
        g_form.addOption('category', 'diversity_inclusion', 'Diversity & Inclusion', 5);
        g_form.addOption('category', 'political_social_cause', 'Political or Social Cause', 6);

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


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

Thank you for the recommendation, I gave that a shot and it did not work either. The select box shows 'disaster/crisis' as the first option

Hi,

It'd be nice to see what you have actually used, so we can verify and all that, but alright.

Can you also try doing this:

g_form.addOption('category', '', '', 1);

and place that both before the clearOptions line and right after. Sounds weird, I know, but give it a shot.

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


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

Daniel R2
Kilo Sage

@mkdj12 - did you manage to resolve this, we are facing a similar issue? 

Where --none-- now does not appear on the second select box after selecting the option in the first select box