Can't change error message for form validation

Douglas Fittipaldi asked on May 13, 2026 19:42

Hello:

We're using version 13.0.138 and I'm trying to set a custom error message for a basic form. All I'm doing is going to the form builder, clicking on the field I want to have validated, specifying a minimum length of one, and filling out the error message box. This is a required field, and I did check the Required field under Properties. When I try out the form, however, the custom error message doesn't show up. It's still the default message. What am I missing?

Correct Answer

Douglas Fittipaldi answered on May 26, 2026 22:48

Debugging showed me that the validation wasn't fired if the field was empty, so I had to rethink how I was approaching this. So, if anyone's curious, here's what I did to get this working:

  1. Make a custom hidden input form component that has a value (any value) in the DefaultValue property.
  2. Make a custom validator to compare this hidden input field to a field you want to validate against. In the Validate method, fetch the value of the field you're comparing against using the DependeeFieldValue variable and put in your code to check if that variable is empty.
  3. In Form Builder, add the hidden input field to the form. Blank out the label and make the field required. You will need to add the hidden field for each input field you want to validate against.
  4. Assign your custom validator to the hidden field. Have it compare against the field you want to make sure isn't blank. That field should not be required. Type in the error message you want to show.

With all of that, I was able to validate an empty field that wasn't required. This seems to work for most of the fields, but I did notice an issue with Multiple Choice and Textarea fields, but that's a different issue, so I think this ticket can be closed. Thanks again for your help.

1 votesVote for this answer Unmark Correct answer

Recent Answers


Juraj Ondrus answered on May 14, 2026 05:13

For a required field the validation you set is not fired. Since it is required, it has no sense to check for minimum length - the field cannot be empty and this is the first thing fired. So, I would try removing the required flag so the validation will get to your custom validation rule.

0 votesVote for this answer Mark as a Correct answer

Douglas Fittipaldi answered on May 14, 2026 14:11

Thanks, Juraj. I did try that but that didn't seem to make a difference. I made one of the required fields not required and I put in the custom validation, but when I submitted the form only the required fields validated. I was able to submit the form and the text field with the minimum length of 1 remained blank.

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on May 15, 2026 12:45

If you want to check for empty value, use a regex. The minimum value validation is fired only if you enter something into the field. The validation is not fired for empty field. Try using minimum length 10 and type a shorter string. The custom validation message should be displayed.

0 votesVote for this answer Mark as a Correct answer

Douglas Fittipaldi answered on May 15, 2026 14:15

Ah, thank you! Using a minimum length of 10 and typing in a shorter string worked and I saw my custom error message. But how would I check for an empty field using regex? I've tried using ^$ and ^\s*$ and neither were fired when I submitted the form.

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on May 18, 2026 06:20

Have you tried using ^(?!.*\S)
If this will not help, then the only other option would be a fully custom validation rule.

0 votesVote for this answer Mark as a Correct answer

Douglas Fittipaldi answered on May 18, 2026 14:14

Thanks for your help.

0 votesVote for this answer Mark as a Correct answer

Douglas Fittipaldi answered on May 19, 2026 17:03

Hi Juraj. I tried both of your suggestions but I didn't get anywhere. It looks like custom validations don't trigger for empty fields (as you've noted previously), and if you make the field required then you just get the standard message. Basically, I'm looking for a way to specify messages like "Please fill in the first name" and "Please check off one of the options above", etc. Is there no way to specify a different custom error message for each required field in a form?

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on May 20, 2026 07:52

How does your custom validation rule looks like? In the code you are checking the value - if null or empty, you can return false and this should fire the validation.

0 votesVote for this answer Mark as a Correct answer

Douglas Fittipaldi answered on May 20, 2026 14:42

Here's what I have for the validate method in a class that inherits from ValidationRule<string>

    protected override bool Validate(string value)
    {
        return !string.IsNullOrWhiteSpace(value);
    }

But it never fires. The form submits without firing. If I make the field required, it gives me the default error message. I put breakpoints in the method and it only gets hit if I put at least one character in the field, but if I leave it blank then it doesn't fire.

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on May 21, 2026 08:25

When you debug the code - it there anything in the "value" variable? I think that if there is nothing filled out in the field -> there is nothing to validate so the validation is not fired.
One option would be to automatically fill the field with some hidden character and validate it against it + the value you want to have there, e.g. the length. Or, another option would be fully custom form component which will have the validation implemented in its code.

0 votesVote for this answer Mark as a Correct answer

Douglas Fittipaldi answered on May 21, 2026 14:36

Thanks for those suggestions. What I tried was making a hidden field from component that had no value and then use the form builder's validation to compare the field I wanted to validate against the empty hidden field. While my custom message did show when I tried to submit without filling the field, the validation would keep firing even after I filled out the field. What am I missing?

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on May 25, 2026 08:43

What does the debug say - what code is hit and what are the values passed into the validation logic?

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.