AngularJS validation errors -
i have working form ngmessages.
my issue when displayed form , empty, not want show errors, when user has focused out input.
is possible?
use $touched
:
snippet:
var app = angular.module('app', ['ngmessages']); app.controller('mainctrl', function($scope) { // js code });
<!doctype html> <html ng-app="app"> <head> <script src="https://code.angularjs.org/1.5.7/angular.js"></script> <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" /> <script src="http://code.jquery.com/jquery-2.0.3.min.js"></script> <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script> <script src="https://code.angularjs.org/1.4.7/angular-messages.js"></script> </head> <body ng-controller="mainctrl"> <form role="form" name="form" novalidate> <div class="col-md-12"> <div class="form-group" ng-class="{ 'has-error' : form.email.$touched && form.email.$invalid }"> <label>name</label> <input type="email" name="email" class="form-control" placeholder="name" ng-model="email" required> <div class="help-block" ng-messages="form.email.$error" ng-if="form.email.$touched"> <p ng-message="required">this field required</p> <p ng-message="minlength">this field short</p> <p ng-message="maxlength">this field long</p> <p ng-message="required">this field required</p> <p ng-message="email">this needs valid email</p> </div> </div> </div> </form> </body> </html>
for more check here.
i hope helps!
Comments
Post a Comment