Custom validation for choice field

Hi,
I'm looking to add some validation to a checkbox field (yes / no) that if the text value = "No" it will not submit the form - In order to proceed Yes must be selected.
Thanks as always!

something similar to this

fd.spRendered(function() {

fd.field('InductionConfirmation').validators.push({
name: 'YesValidation',
error: "You must have completed Step 1 in order to submit this form",
validate: function(value) {
if(value=="No"){
return false;
}
return true;
}
});

}

Hello @flowy,

Yes/No field value is a boolean, so the condition should be:

if(value == false)

I've updated your code:

fd.spRendered(function() {

        fd.field('InductionConfirmation').validators.push({
                name: 'YesValidation',
                error: "You must have completed Step 1 in order to submit this form",
                validate: function(value) {
                if(value == false){
                        return false;
                }
                        return true;
                }
        });

});

You can find more information about the Yes/No field here.

1 Like

Thanks for your response. I should have added that the column is a choice field pulling the text Yes or No and not a boolean Yes/No field. I've gotten around it by getting rid of the No choice (pointless having it anyway!) and adding:

validate: function(value) {
if (!fd.field('InductionConfirmation').value)
return false;
return true;

Thank you for your help as always though.

1 Like