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.

$setViewValue makes invalid field blank if using attribute «pattern» #9986

Closed
@artuska

Description

@artuska

Plunker — http://plnkr.co/edit/54otaclvjjZUW63vR9QT?p=preview

There I have two input fields and two directives — the only difference in this fields and directives is that one has «pattern="a-z"» attribute and other has «blabla="a-z"» attribute.

The one with «pattern» attribute doesn't work — $setViewValue() makes it blank if it does not fit the pattern regexp.

So, what is the problem with this «pattern» attribute — why does it brake everything? Does Angular use both «pattern» and «ng-pattern» attribute to validate input field? Why «pattern» attribute makes field blank if it is not valid?

Also, I have changed «pattern» to «ng-pattern» and it resolved the problem:

<input type="text" name="foo" ng-pattern="a-z" ng-model="user.foo" working-input>

and in directive:

var pattern = attributes.ngPattern;

I'm creating this issue for those who has the same problem and spend about 30 minutes to resolve it (because renaming «pattern» attribute to something else really is not obvious).

(I have found some issues here but they all are about $asyncValidators)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions