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

Commit fe8a298

Browse files
committed
feat(input): use ValidityState for required state
Change NgModelController $isEmpty method to consider HTML5 constraint validation in supporting browsers, fallback to normal empty data check
1 parent 5af9454 commit fe8a298

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/ng/directive/input.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -1613,12 +1613,7 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$
16131613
* @returns {boolean} True if `value` is empty.
16141614
*/
16151615
this.$isEmpty = function(value) {
1616-
var validity = $element.prop('validity');
1617-
if (isObject(validity)) {
1618-
return validity.valueMissing;
1619-
} else {
1620-
return isUndefined(value) || value === '' || value === null || value !== value;
1621-
}
1616+
return isUndefined(value) || value === '' || value === null || value !== value;
16221617
};
16231618

16241619
var parentForm = $element.inheritedData('$formController') || nullFormCtrl,
@@ -2064,8 +2059,15 @@ var requiredDirective = function() {
20642059
if (!ctrl) return;
20652060
attr.required = true; // force truthy in case we are on non input element
20662061

2062+
var validity = elm.prop('validity');
2063+
if (!isObject(validity)) {
2064+
validity = {
2065+
valid: true
2066+
};
2067+
}
2068+
20672069
var validator = function(value) {
2068-
if (attr.required && ctrl.$isEmpty(value)) {
2070+
if (attr.required && (validity.valueMissing || ctrl.$isEmpty(value))) {
20692071
ctrl.$setValidity('required', false);
20702072
return;
20712073
} else {

0 commit comments

Comments
 (0)