[RESOLVED] Conditional not working

Hi,

I have cooked up this conditional but it doesn't seem to be working for Multi choice checkbox fields. This code isn't fully complete but I just wanted to test if it works for this type of field before I push ahead and do the rest.

  //This will show hide tabs based on the checkbox selected
    fd.spRendered(function(){
        function showhidetabs(){
            if (fd.field('Question_2').value == 'Name'){
            fd.container('Tab0').tabs[1].disabled = true;
            fd.container('Tab0').tabs[2].disabled = true
            fd.container('Tab0').tabs[3].disabled = true;
            fd.container('Tab0').tabs[0].disabled = false;
            fd.container('Tab0').setTab(0);
             
            }
            
            if (fd.field('Question_2').value == 'Address' && fd.field('Question_2').value == 'Name'){
            fd.container('Tab0').tabs[2].disabled = true
            fd.container('Tab0').tabs[3].disabled = true;
            fd.container('Tab0').tabs[0].disabled = false;
            fd.container('Tab0').tabs[1].disabled = false;
            fd.container('Tab0').setTab(0);
            fd.container('Tab0').setTab(1);
            }          
             
        }
        
        //call TabHider when a user changes the status
        fd.field('Question_2').$on('change',showhidetabs);
        
        //call TabHider on form load
        showhidetabs();
    });

Here is what the field looks like on the form:

image

Hello @DryChips,

Multiple Choice field value is stored as an array of strings.

To check if a particular value is selected, use this code:

if(fd.field('Field1').value.includes('Choice 1')){
    console.log('Choice 1 is selected');
}
1 Like

Hi Mnikitina,

Thanks for this!

I have a quick question, how can I optimize this code:

if (fd.field('Question_2').value.includes('Name') && fd.field('Question_2').value.includes('Address'))

Instead of typing up the same statement after &&, is it possible to put into one if statement?

Here is an example, the syntax isn't correct but something like this would be much better to type and save space in the JS editor..

if (fd.field('Question_2').value.includes = ['Name', 'Phone/Email Address'])

It's cool, I fixed the problem.

1 Like