Making another field required or not required if all choices in a multiple choice field is selected

Hello,
I'm placing Plumsail form code into our public website for a browser and trying to make field2 not required if another multiple choice field's options have all been selected. If at least one of the multiple choice field's options have not been selected then field2 is required. I can't seem to get this to work correctly as it keeps on making field2 required even after I select all of the multiple choice field's options. Here's my code:

fd.rendered(function() {
    
fd.field('multiplechoice1').$on('change', function(options) {
        if(options.indexOf('String of text option 1.') >= 0 && options.indexOf('String of text option 2.') >= 0 && options.indexOf('String of text option 3.') >= 0) {
            fd.field('field2').required = false;
        } else {
            fd.field('field2').required = true;
        }  
    });
    
    //Calling options when multiplechoice1 value changes
    fd.field('multiplechoice1').$on('change', options);
});

Not sure this matters but multiplechoice1 is also actually a required field preset in Plumsail forms designer. Thank you.

Dear @lso,
The code should work, here - MultiChoiceRequired

This is the code that I've used, based on your sample:

fd.rendered(function() {
    fd.field('MultiChoice1').$on('change', function(options) {
        if(options.indexOf('Item 1') >= 0 && options.indexOf('Item 2') >= 0 && options.indexOf('Item 3') >= 0) {
            fd.field('MultiChoice2').required = false;
        } else {
            fd.field('MultiChoice2').required = true;
        }  
    });
});

Check console for errors, maybe there is a typo in a string or a field name, or some other error.

1 Like