The first thing you did not have enough to add ng-model='name' to the input field, then the only form will become invalid when you click submit, otherwise the form will always be valid, since it considers that it does not have a field.
Then I add the submitted class to the submit button click, and then set the css border as .submitted will be the parent and .ng-invalid will be the child, so we can put the style in .submitted .ng-invalid
HTML
<div ng-controller="MyCtrl"> <form class="well" name="formTest" ng-class="{'submitted': submitted}" ng-submit="save()" > <div class="form-group"> <label for="name">Name*</label> <input type="name" class="form-control" id="name" placeholder="Enter name" ng-model="name" required /> </div>{{submitted}} <button type="submit" class="btn btn-default" ng-click="submitted= true;">Submit</button> </form> </div>
CSS
.submitted .ng-invalid{ border: 1px solid red; }
Working script
Hope this helps you, thanks.
source share