Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed error messages for Required and EnforceClientFormat validators #1589

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tomasherceg
Copy link
Member

I noticed that the Required validator works on non-nullable value types, but it produces incorrect error messages.

For example, if you bind a TextBox on a DateTime property with the Required validator and enter an invalid value in the control, the error message which appeared was this:

Cannot coerce 'null' to type 'DateTime'.

This is an internal error message for developers, not for the end users.

When the control writes the null value in the observable via the dotvvm-textbox-text binding handler, an error is thrown. The binding handler stores the validation error (as a lastSetErrorSymbol) and shows it during the validation together with other errors, and the old value remains in the observable.

I've changed the behavior to be like this:

  • The Required client-side validator checks whether the observable value is empty. If not, the associated field can still be empty - it will look at the bound elements and if any of them is in an invalid state and its value is empty, it will produce the error.

  • The EnforceClientFormat produce a validation error only if it finds an associated element in an invalid state with non-empty value (or with an empty value if such value is not permitted). This condition was added to avoid producing an error when the required validator had already produced it.

  • The error from lastSetErrorSymbol is displayed only when the property doesn't have any other validation errors. If there is any other error, it would probably be connected to this; thus, we won't show this internal error message to the user. Typically, if the property doesn't have any validation attributes, this internal message from the coercer would be shown. The user will see a meaningful error message if the property has the validation attribute.

Do you have any ideas if this change is safe to do and what we can break by doing this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant