Issue with clearoptions and removeoption

Fiske
Tera Contributor

Hello Community,
Based on the situation I need to remove some options and add others in choice data fields depending on a parent field. To tackle this situation, I am clearing all options and adding specific options during onChange.

 

The issue is that when I am clearing or removing options and adding new ones, the options are added in the dropdown, but the text is not visible.

 

Below is the code:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    g_form.clearOptions('factory_issue');
    if (newValue == 'inlet_inventory') {
        g_form.addOption('factory_issue', 'out_of_stock');
        g_form.addOption('factory_issue', 'power_failure');
        g_form.addOption('factory_issue', 'internet_failure');
        g_form.addOption('factory_issue', 'storage_capacity_exceeded');
    } else if (newValue == 'manufacturing_department') {
        g_form.addOption('factory_issue', 'machine_issue');
        g_form.addOption('factory_issue', 'power_failure');
        g_form.addOption('factory_issue', 'internet_failure');
        g_form.addOption('factory_issue', 'out_of_stock');
    }

}
 
1 ACCEPTED SOLUTION

Amit Pandey
Kilo Sage

Hi @Fiske 

 

Because you're writing the options to show. Modify it as follows-

 

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

    if (newValue == 'inlet_inventory') {
        g_form.addOption('factory_issue', 'out_of_stock', 'Out of Stock');
        g_form.addOption('factory_issue', 'power_failure', 'Power Failure');
        g_form.addOption('factory_issue', 'internet_failure', 'Internet Failure');
        g_form.addOption('factory_issue', 'storage_capacity_exceeded', 'Storage Capacity Exceeded');
    } else if (newValue == 'manufacturing_department') {
        g_form.addOption('factory_issue', 'machine_issue', 'Machine Issue');
        g_form.addOption('factory_issue', 'power_failure', 'Power Failure');
        g_form.addOption('factory_issue', 'internet_failure', 'Internet Failure');
        g_form.addOption('factory_issue', 'out_of_stock', 'Out of Stock');
    }
}

Please mark my answer helpful and correct.

 

Regards,

Amit

View solution in original post

2 REPLIES 2

Amit Pandey
Kilo Sage

Hi @Fiske 

 

Because you're writing the options to show. Modify it as follows-

 

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

    if (newValue == 'inlet_inventory') {
        g_form.addOption('factory_issue', 'out_of_stock', 'Out of Stock');
        g_form.addOption('factory_issue', 'power_failure', 'Power Failure');
        g_form.addOption('factory_issue', 'internet_failure', 'Internet Failure');
        g_form.addOption('factory_issue', 'storage_capacity_exceeded', 'Storage Capacity Exceeded');
    } else if (newValue == 'manufacturing_department') {
        g_form.addOption('factory_issue', 'machine_issue', 'Machine Issue');
        g_form.addOption('factory_issue', 'power_failure', 'Power Failure');
        g_form.addOption('factory_issue', 'internet_failure', 'Internet Failure');
        g_form.addOption('factory_issue', 'out_of_stock', 'Out of Stock');
    }
}

Please mark my answer helpful and correct.

 

Regards,

Amit

Community Alums
Not applicable

Hi @Fiske ,

I tried your problem on my PDI and I hope my solution helps you, please refer below code

 

if (newValue == 2) {
        g_form.addOption('state', 11, '6 - Really Low');
    }

If you want to add option in dropdown fields you need to give both frontend name and backend name 

You can do like this

 

Please mark correct and helpful if this works for you

 

Thanks and Regards

Sarthak