Skip to content

Is HTML5-validation supported? #20717

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

Closed
pekspro opened this issue Apr 10, 2020 · 7 comments
Closed

Is HTML5-validation supported? #20717

pekspro opened this issue Apr 10, 2020 · 7 comments
Labels
affected-very-few This issue impacts very few customers area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-mvc-razor-views Features related to the Razor view engine for Razor pages and MVC views severity-major This label is used by an internal tool
Milestone

Comments

@pekspro
Copy link

pekspro commented Apr 10, 2020

In the documentation it says for the input tag helper:

Generates HTML5 validation attributes from data annotation attributes applied to model properties.

But if I have an property like this:

[Required]
[StringLength(10, MinimumLength = 5)]
[Display(Name = "Computer name")]
public string ComputerName { get; set; }

And then uses the input tag like this:

<input asp-for="ComputerName" class="form-control" />

It becomes generated like this:

<input class="form-control" type="text" data-val="true" 
data-val-length="The field Computer name must be a string with a minimum length of 5 and a maximum length of 10." 
data-val-length-max="10" data-val-length-min="5" 
data-val-required="The Computer name field is required." id="ComputerName" 
maxlength="10" name="ComputerName" value="">

There is no minlength and required attribute as expected. Also, the form tag is generated with the novalidate attribute which to my understanding disables HTML5 validation.

I’ve also tried to disable client-side validation. This removes the novalidate attribute on the form tag, but the minlength and required attribues is still missing.

To summary, is HTML5 validation supported as it mentioned in the documentation?

Issue 8573 is a bit related to this.

I’m asking only by curiosity :-)

@javiercn javiercn added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Apr 10, 2020
@mkArtakMSFT mkArtakMSFT added the enhancement This issue represents an ask for new feature or an enhancement to an existing one label Apr 13, 2020
@mkArtakMSFT mkArtakMSFT added this to the Backlog milestone Apr 13, 2020
@mkArtakMSFT
Copy link
Contributor

mkArtakMSFT commented Apr 13, 2020

This is not yet support.
We've moved this issue to the Backlog milestone. This means that it is not going to happen for the coming release. We will reassess the backlog following the current release and consider this item at that time. However, keep in mind that there are many other high priority features with which it will be competing for resources.

@captainsafia captainsafia added affected-very-few This issue impacts very few customers severity-major This label is used by an internal tool labels Nov 6, 2020
@javiercn javiercn added the feature-mvc-razor-views Features related to the Razor view engine for Razor pages and MVC views label Apr 18, 2021
@XmlmXmlmX
Copy link

Wow, that's really hard to believe. Open for 2 years.

@RihanArfan
Copy link

RihanArfan commented Oct 11, 2022

The dependence on a jQuery library for client validation in 2022 is quite concerning mainly as it's very legacy, performance, accessibility, etc. Vanilla JavaScript itself has come a long way and even GOV.UK have scrapped jQuery fully for native JS. Regardless, validation can be done fully without JS nicely.

All modern browsers have built in HTML5 validation which is really simple to use and works natively. https://developer.mozilla.org/en-US/docs/Learn/Forms/Form_validation

It's just a matter of switching the tags that are added to forms inputs (asp-for) to the HTML5 replacements. Stuff like data-val-required to required and data-val-length-min to minlength.

Some HTML5 attributes like maxlength are already added. ([StringLength(30, MinimumLength = 3)])

Internet explorer is EOL and not something that has to be considered anymore.

I don't think this would be a difficult thing to do and it'd modernise .NET Core a lot.

@javiercn
Copy link
Member

We are going to use #8573 to track work in this area.

As for HTML5 validation specifically, we do not think it is a good fit as we identified some gaps compared to the current experience the last time we evaluated it.

@javiercn javiercn removed their assignment Oct 19, 2022
@javiercn javiercn closed this as not planned Won't fix, can't repro, duplicate, stale Oct 19, 2022
@denschub
Copy link

@javiercn what are those "gaps"? From a browser developer's standpoint, I'd be interested in learning about those.

@javiercn
Copy link
Member

@denschub I would need to dig into the details (we had this discussion many months ago and the developer on point is no longer part of the team), but I believe some of them were:

  • Different UIs across browsers.
  • Customizing the UI
  • Custom error messages
  • Error summary
  • Async validation

Some of these might be possible (even though at the expense of writing code), but in general html5 validation works very differently from our current validation system and we would like to maintain backwards compatibility where possible.

@denschub
Copy link

Understood, yeah. There's probably some things you can already do with native APIs. For example, an Error summary could be built by iterating over form elements and reading HTMLObjectElement.validationMessage. Custom error messages can be set via HTMLObjectElement.setCustomValidity, etc. But I assume there's still a lot of things not possible, so feel free to file an issue in the HTML spec if you have any specific feature request!

None of that won't help with full backwards compatibility, of course. I was just curios, so thanks for the feedback!

@ghost ghost locked as resolved and limited conversation to collaborators Nov 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affected-very-few This issue impacts very few customers area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-mvc-razor-views Features related to the Razor view engine for Razor pages and MVC views severity-major This label is used by an internal tool
Projects
None yet
Development

No branches or pull requests

7 participants