Call a function on Valid Blur

PLUNKER

How can I call the function call on blur only if the element is valid, there is no other error?

Html

<input type="text" id="order" ng-model="order" name="order" class="form-control" 
    ng-pattern="/^[0-9]*$/" ng-minlength="9" maxlength="9"
    required="" ng-blur="something()"  />

      

Js

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope) {
    $scope.something=function(){
      if($scope.routingNumber.$valid)
        alert("yippie");
    }
});

      

+3


source to share


1 answer


You will find here: http://plnkr.co/edit/g4ecmWToQPbOKAk3XvNt?p=preview (full form) http://plnkr.co/edit/Zep8D4AXvkzwpqcFFXjR?p=preview (only for order field)

You just need to pass yours to form

your method something

.

<input type="text" id="order" ng-model="order" name="order" class="form-control" 
 ng-pattern="/^[0-9]*$/" ng-minlength="9" maxlength="9"
 required="" ng-blur="something(myform)"  />

      



And in your JS:

app.controller('MainCtrl', function($scope) {
  $scope.something = function(form) {
    if (form.order.$valid) {
      alert("yippie");
    }
  }
});

      

More information on form validation and docs errors can be found: https://docs.angularjs.org/guide/forms

+5


source







All Articles