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.

ngModelController.$setViewValue() on invalid field keeps validation error #12713

@edzius

Description

@edzius

The problem is with input[number] field. When i change value to invalid and uncheck checkbox field should reset value to last valid one and thus there should be no validation error. View value is changed back but validation value is still present.

See the demo: http://plnkr.co/edit/qIFxmVEXowSNGaBifV4T?p=preview

By digging some into angular, whole problem seems to be automatically added "badInputChecker" $parser. It checks element ValidityState without respect to new value and in consequence returns undefined to model.

Workaround could be before $setViewValue() to set new value for input and perform checkValidity():

  // Set new input value and do checkValidity() that updates input ValidityState
  var tmp = input.val();
  input.val(valid);
  input[0].checkValidity()
  input.val(tmp);
  // Do standard angular $setViewValue()
  inputCtrl.$setViewValue(valid);
  inputCtrl.$render();

Any ideas or plans how can this be solved in angularjs?

Cheers,
Edvinas

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions