Date Field Validation

Hi all!

We had assistance from Plumsail in the past to help create a validation on a date field to ensure that it was in the right format on our Plumsail Public Form. The issue I am having is that when the date field is hidden from view, the validation still runs and throws an error to the user, prohibiting them from submitting the form. This obviously causes confusion since the date field isn't even visible.

I am wondering if there is a way to disable the validation on a field so that I can execute that when hiding the field OR is there a way that I can add an additional field into the validation check so that it only validates if the date is in the wrong format AND the text field does NOT equal a certain value. Current code is below:

fd.validators.push(
{
name: 'Date',
error: 'Please enter a valid incident date in the following format 1/1/20XX',
validate: function(value) {
if (fd.field('DateOfIncident').value) {
return false;
}
return true;
}
});

Hello @kkreitzer,

You can use a field validator instead of a form validator so that you can remove the validation when hiding the field:

//add field validation
fd.field('DateOfIncident').validators.push({
    name: 'Date',
    error: 'Please enter a valid incident date in the following format 1/1/20XX',
    validate: function(value) {
        if (value) {
            return false;
        }
        return true;
    }
});

//clear validation
fd.field('DateOfIncident').validators.length = 0