Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angularjs ng-model-options is not working.

Tags:

angularjs

I have a pattern on my controller

 $scope.pattern = {
    name: /[a-zA-Z]{5,}/
 }

On the view

<input type="text" name="name" data-ng-model="name" ng-model-options="{ updateOn: 'blur' }"  ng-pattern="pattern.name" required />
      <div ng-show="contactForm.name.$dirty && contactForm.name.$invalid">
        <span ng-show="contactForm.name.$error.required">The name field is mandatory</span>
        <span ng-show="contactForm.name.$error.pattern">The name must be at least 5 characters long</span>
      </div>

I want the field to be validate only when it looses the focus but it doesn't it validates every time I press a button.

like image 816
Petran Avatar asked May 23 '14 18:05

Petran


1 Answers

ngModelOptions was introduced only in Angular 1.3.x

https://docs.angularjs.org/api/ng/directive/ngModelOptions

If you want to use similar functionality in Angular 1.2.x, check out this poly fill:

https://github.com/fergaldoyle/modelOptions

like image 100
Fergal Avatar answered Oct 04 '22 22:10

Fergal