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

Error ng-invalid-date - (Solutions in badInputChecker() ) #12853

Closed
@mxnho

Description

@mxnho

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions