2
votes

Could you please tell how to show red border in the input field on a button in angularJs . Currently, the red border is displayed when the application load. Actually, I added ng-required validation on my form .but I want this only work after button click here is my code http://plnkr.co/edit/zL0cueTJN6xqxC4LzhOd?p=preview

<div class="form-group" ng-class="{'has-error': myform[key].$invalid}">
                                    <input type="text" name="{{key}}" class="form-control" ng-model="value.value" ng-required="value.required">
                                  </div>
1

1 Answers

0
votes

Declare a variable $scope.isSubmitClicked=false; in scope and make it true in submit()

$scope.isSubmitClicked = false;
$scope.submit = function ($event) {           
    $scope.isSubmitClicked = true;
};

Then

<input type="text" name="{{key}}" class="form-control" ng-model="value.value" ng-required="value.required && isSubmitClicked">