Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

input directive does not update html5 native validation. #5500

Closed
refactorthis opened this issue Dec 21, 2013 · 4 comments
Closed

input directive does not update html5 native validation. #5500

refactorthis opened this issue Dec 21, 2013 · 4 comments

Comments

@refactorthis
Copy link

Just an idea, not an issue. Perhaps the $setValidity method in the input directive could call the HTML5 constraint validation api?

Some validation attributes are the same as the standard html5 attributes and will cause native browser validation, however others will not. Perhaps we could force the input directive to be more html5 compatible by integrating better with the element.validity.* properties?

@caitp
Copy link
Contributor

caitp commented Dec 21, 2013

One of my patches tries to do this sort of (at least for type=number), although it doesn't make any calls to checkValidity() or anything... There are some issues with it, but if you'd care to take a look, it would be appreciated. #4293

@IgorMinar
Copy link
Contributor

this should be simple to implement for everything using ngModel directive. We should just update the validity state somewhere in $setValidity method of NgModelController.

the only tricky thing that will require some experimentation is to make sure that by setting that property we don't trigger some native form behavior that would interfere with existing user interface (native browser validation popovers etc).

@refactorthis
Copy link
Author

Yeah that's what I was thinking. From there you easily have access to the element and the validationErrorKey. I believe the submit event must be called for validation to take place so setting the property won't trigger any changes to the UI until the submit event has been raised.

I don't see many side effects as some attributes (min, max) would be causing this already unless the form has the novalidate attribute on it. This change would make the experience more consistent so that all validation will cause HTML5 validation unless novalidate is specified. I guess we would need to experiment with multiple validation functions on one element, as AFAIK the HTML5 spec only allows for one error message at a time.

Would also allow for styling of inputs in a more standardized manner via the :invalid and :valid psuedo classes.

@caitp
Copy link
Contributor

caitp commented Dec 21, 2013

ValidityState doesn't expose any writable properties, the best you can really do is politely ask the browser to do it, and it might decide not to. To be honest, the logic in blink/webkit for this is a bit tricky to follow, and it isn't spelled out super clearly in the draft --- So there may be some issues in doing this consistently across browsers. There are instances where the form control's novalidate is entirely ignored, or where willValidate has an unexpected value for the surrounding markup, etcetera. It's sort of bizarre.

caitp added a commit to caitp/angular.js that referenced this issue Jan 23, 2014
In browsers where HTML5 constraint validation is (partially) implemented, an invalid number
entered into an input[type=number] (for example) input element would be visible to the
script context as the empty string. When the required or ngRequired attributes are not used,
this results in the invalid state of the input being ignored and considered valid.

To address this, a validator which considers the state of the HTML5 ValidityState object is
used when available.

Closes angular#4293
Closes angular#2144
Closes angular#4857
Closes angular#5120
Closes angular#4945
Closes angular#5500
caitp added a commit to caitp/angular.js that referenced this issue Jan 23, 2014
In browsers where HTML5 constraint validation is (partially) implemented, an invalid number
entered into an input[type=number] (for example) input element would be visible to the
script context as the empty string. When the required or ngRequired attributes are not used,
this results in the invalid state of the input being ignored and considered valid.

To address this, a validator which considers the state of the HTML5 ValidityState object is
used when available.

Closes angular#4293
Closes angular#2144
Closes angular#4857
Closes angular#5120
Closes angular#4945
Closes angular#5500
caitp added a commit to caitp/angular.js that referenced this issue Jan 23, 2014
In browsers where HTML5 constraint validation is (partially) implemented, an invalid number
entered into an input[type=number] (for example) input element would be visible to the
script context as the empty string. When the required or ngRequired attributes are not used,
this results in the invalid state of the input being ignored and considered valid.

To address this, a validator which considers the state of the HTML5 ValidityState object is
used when available.

Closes angular#4293
Closes angular#2144
Closes angular#4857
Closes angular#5120
Closes angular#4945
Closes angular#5500
caitp added a commit to caitp/angular.js that referenced this issue Jan 23, 2014
In browsers where HTML5 constraint validation is (partially) implemented, an invalid number
entered into an input[type=number] (for example) input element would be visible to the
script context as the empty string. When the required or ngRequired attributes are not used,
this results in the invalid state of the input being ignored and considered valid.

To address this, a validator which considers the state of the HTML5 ValidityState object is
used when available.

Closes angular#4293
Closes angular#2144
Closes angular#4857
Closes angular#5120
Closes angular#4945
Closes angular#5500
caitp added a commit to caitp/angular.js that referenced this issue Feb 21, 2014
In browsers where HTML5 constraint validation is (partially) implemented, an invalid number
entered into an input[type=number] (for example) input element would be visible to the
script context as the empty string. When the required or ngRequired attributes are not used,
this results in the invalid state of the input being ignored and considered valid.

To address this, a validator which considers the state of the HTML5 ValidityState object is
used when available.

Closes angular#4293
Closes angular#2144
Closes angular#4857
Closes angular#5120
Closes angular#4945
Closes angular#5500
caitp added a commit to caitp/angular.js that referenced this issue Feb 21, 2014
In browsers where HTML5 constraint validation is (partially) implemented, an invalid number
entered into an input[type=number] (for example) input element would be visible to the
script context as the empty string. When the required or ngRequired attributes are not used,
this results in the invalid state of the input being ignored and considered valid.

To address this, a validator which considers the state of the HTML5 ValidityState object is
used when available.

Closes angular#4293
Closes angular#2144
Closes angular#4857
Closes angular#5120
Closes angular#4945
Closes angular#5500
caitp added a commit to caitp/angular.js that referenced this issue Feb 21, 2014
In browsers where HTML5 constraint validation is (partially) implemented, an invalid number
entered into an input[type=number] (for example) input element would be visible to the
script context as the empty string. When the required or ngRequired attributes are not used,
this results in the invalid state of the input being ignored and considered valid.

To address this, a validator which considers the state of the HTML5 ValidityState object is
used when available.

Closes angular#4293
Closes angular#2144
Closes angular#4857
Closes angular#5120
Closes angular#4945
Closes angular#5500
@caitp caitp closed this as completed in c2d447e Feb 21, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants