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

Client validation with RangeAttribute #59722

Open
McVanS opened this issue Jan 5, 2025 · 0 comments
Open

Client validation with RangeAttribute #59722

McVanS opened this issue Jan 5, 2025 · 0 comments
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates

Comments

@McVanS
Copy link

McVanS commented Jan 5, 2025

Recently I revisited an old MVC concept and started updating some of the components to .Net 9. I started updating my JavaScript client validation code and ran into a problem with the RangeAttribute.

The new RangeAttribute now supports MinimumIsExclusive and MaximumIsExclusive parameters.

[Range(1,10)] renders HTML attributes
data-val="true" data-val-range="The field Test must be between 1 and 10." data-val-range-max="10" data-val-range-min="1"

[Range(1,10,MinimumIsExclusive = true, MaximumIsExclusive = false)] renders HTML attributes
data-val="true" data-val-range="The field Test must be between 1 exclusive and 10." data-val-range-max="10" data-val-range-min="1"

[Range(1,10,MinimumIsExclusive = false, MaximumIsExclusive = true)] renders HTML attributes
data-val="true" data-val-range="The field Test must be between 1 and 10 exclusive." data-val-range-max="10" data-val-range-min="1"

[Range(1,10,MinimumIsExclusive = false, MaximumIsExclusive = true)] renders HTML attributes
data-val="true" data-val-range="The field Test must be between 1 exclusive and 10 exclusive." data-val-range-max="10" data-val-range-min="1"

Note the default error messages correctly reflects the intension. The actual server sider validation works as expected.

Historically for client validation one would retrieve a data attribute from an input element to do client validation with. A data attribute indicating the exclusive state of the minimum and/or maximum value(s) is absent in the generated HTML element. Except for the error message there is no other way one can determine the exclusive state of the value

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Jan 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates
Projects
None yet
Development

No branches or pull requests

1 participant