Checking multiple Fields with Condition

Hello,

I´m able to check one Field for example: Choice1 if this is != '1' i can make Note1 a requierd field.
Now i need help in checking multiple fields.
Note1 should be a requeired field if Choice1 & Choice2 & Choice3 != '1'.

Your Help appreciated
Paul

Hello @Paul21,

Welcome to Plumsail Community!

You can use the code below to make Note1 field required if choice field values doesn't equal 1.

fd.validators.push({
    name: 'Validate Note1',
    error: "Note1 is required",
    validate: function(value) {
        if(fd.field('Choice1').value != "Item 1" && fd.field('Choice2').value != "Item 1" && fd.field('Choice3').value != "Item 1") {
            if (!fd.field('Note1').value) {
            return false;
            }
        }
        return true;
    }
});

Wrap the code inside fd.spRendered() if you are using Forms for SharePoint, and inside fd.rendered() if you are using Public Forms. Like this:

fd.rendered(function() {
    fd.validators.push({
        name: 'Validate Note1',
        error: "Note1 is required",
        validate: function(value) {
            if(fd.field('Choice1').value != "Item 1" && fd.field('Choice2').value != "Item 1" && fd.field('Choice3').value != "Item 1") {
                if (!fd.field('Note1').value) {
                return false;
                }
            }
            return true;
        }
    });
});
1 Like