How to change default error message for required field?

Hi,

I am trying to change the default error message on a form to say something custom rather than "This field is required".

Is there anything I can do?

Thanks.

image

Hello @ProfessorProton12,

Welcome to Plumsail Community!
You can use this code to change the default message:

fd.created(() => {
    fd.messages.RequiredValidator_Error = "Some new text."
});

Please learn more in Form Manager of public web forms article.

1 Like

Hi mnikitina, thanks for this.

This is working well but does not give me the ability to control specific error messages on different fields since it's a global property.

Is there anyway to specific specific fields?

Thank you.

@ProfessorProton12,

You can add custom validation to each field with individual error messages using the code:

fd.rendered(() => {
    fd.field('Field1').addValidator({
        name: 'Custom validator',
        error: 'My custom error message',
        validate: function(value) {
            if (!value) {
                return false;
            }
            return true;
        }
    });
});

Thank you for this solution. When I input the code it seems to be overlapping with the Global property of the error message:

This is the code I have implemented:

Do you have any idea why this could be?

Thank you!

@ProfessorProton12,

Do you make field required in the designer?
image

Make it optional when using the code:

fd.rendered(() => {
    fd.field('Field1').addValidator({
        name: 'Custom validator',
        error: 'My custom error message',
        validate: function(value) {
            if (!value) {
                return false;
            }
            return true;
        }
    });
});
1 Like