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

How to hide field choices based on the other field choice selected in interaction form?

Deepika61
Tera Contributor

Hi All,

 

Actually i have a requirement that in interaction for we have two choice  fields 'case type' and 'Transmitted' , So in that if case type is support then in the Transmitted field need to display two choices(channel, calls) , for ther case types , that two choices(Channel, calls) need to hide?

 

Please help me to achieve this?

 

Thanks

Deepika

5 REPLIES 5

@Deepika61 ,

 

I saw one small mistake, I have rectified that in below code. Also make sure you are replacing all the 'name' and 'value' attribute of objects in array properly 

 

unction onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
/*In the below array of objects name is the display name of option and value is backend name of option*/
    var transmittedOptions = [{
        "name": "ABC",
        "value": "abc"
    }, {
        "name": "Def",
        "value": "def"
    }, {
        "name": "Channel",
        "value": "channel"
    }, {
        "name": "Hij",
        "value": "hij"
    }, {
        "name": "Calls",
        "value": "calls"
    }]; //comma separated list of objects of transmitted field option
    if (g_form.getValue("case_type") == "support") {
        g_form.clearOptions("transmitted_field_name");
        transmittedOptions.forEach(function(opt) {
            if (opt.value == "channel")
                g_form.addOption("transmitted_field_name", opt.value, opt.name);
            if (opt.value == "calls")
                g_form.addOption("transmitted_field_name", opt.value, opt.name);
            g_form.removeOption("transmitted_field_name", opt.value);
        });
    } else {
        g_form.clearOptions("transmitted_field_name");
        transmittedOptions.forEach(function(opt) {
            if (opt.value == "channel") // use proper backend name of your option, I have used 'channel'
                g_form.removeOption("transmitted_field_name", opt.value);
            if (opt.value == "calls") // use proper backend name of your option, I have used 'calls'
                g_form.removeOption("transmitted_field_name", opt.value);
            g_form.addOption("transmitted_field_name", opt.value,opt.name);
        });
    }

}

 

I hope this helps.

 

Regards,

Kamlesh