aspnetcore icon indicating copy to clipboard operation
aspnetcore copied to clipboard

DefaultHtmlGenerator could add min and max HTML attributes based on RangeAttribute

Open rjpowers10 opened this issue 3 years ago • 1 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

I add the RangeAttribute to specify a min and max value for my number input.

[Range(1, 10)]
public int Quantity { get; set; }

As expected, I get the data-val, data-val-range, data-val-range-min, and data-val-range-max attributes on my input. The client-side validation works correctly, but it seems like reasonable behavior to also set the min and max attributes. That way the browser can enforce the range so the user can't enter a bad value to begin with.

There is precedent for this with MaxLengthAttribute and StringLengthAttribute.

We can see here that the DefaultHtmlGenerator.AddMaxLengthAttribute method adds the maxlength HTML attribute when either MaxLengthAttribute or StringLengthAttribute is present.

Describe the solution you'd like

DefaultHtmlGenerator could have an AddMinAndMaxAttributes method that adds the min and max HTML attributes if the RangeAttribute is present.

Additional context

No response

rjpowers10 avatar Sep 16 '22 20:09 rjpowers10

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

ghost avatar Sep 22 '22 16:09 ghost