Error ng-invalid-date - (Solutions in badInputChecker() ) #12853
Description
I have a input type = "Date" not required in my form linked to a
ng - model = "date" , when I add a value to the component
and then use the delete key to erase the value , the angular adds
the ng -invalid class component and adds to the value undefined , making my form
invalid.
The solution would be changing the function which adds badInputChecker undefined
for the component , that function should be changed to set null instead of undefined.
Thus, the component will only be invalid if required .
function badInputChecker(scope, element, attr, ctrl) {
var node = element[0];
var nativeValidation = ctrl.$$hasNativeValidators = isObject(node.validity);
if (nativeValidation) {
ctrl.$parsers.push(function(value) {
var validity = element.prop(VALIDITY_STATE_PROPERTY) || {};
// Detect bug in FF35 for inputemail:
// - also sets validity.badInput (should only be validity.typeMismatch).
// - see http://www.whatwg.org/specs/web-apps/current-work/multipage/forms.html#e-mail-state-(type=email)
// - can ignore this case as we can still read out the erroneous email...
//return validity.badInput && !validity.typeMismatch ? undefined: value; old
return validity.badInput && !validity.typeMismatch ? null : value; //new
});
}
}
Best regards