I have an form with 3 input fields, who will validate. Important is to change the error respectively success class when the user does an interaction with the form.
<form class="form-horizontal" name="myForm" novalidate>
<div class="form-group-sm has-feedback" ng-class="{ 'has-error' : myForm.Name.$invalid && !myForm.Name.$pristine || myForm.Name.$touched }">
<label class="control-label" for="name-id">Name</label>
<input type="text"
class="form-control"
placeholder="Name"
name="Name"
ng-model="selected.name"
ng-pattern="/^[a-zA-Z]+/"
ng-required="true"
/>
<p class="help-block" ng-show="myForm.Name.$error.required && myForm.Name.$touched">Name is required</p>
<p class="help-block" ng-show="myForm.Name.$error.pattern">Name must be written with letters</p>
</div>
...
When the user considered the required field and the pattern then after the interaction with the input field, it should be changes the css class to has-success.
I've tried this:
<div class="form-group-sm has-feedback" ng-class="myForm.Name.$invalid && !myForm.Name.$pristine && myForm.Name.$touched ? 'has-error' : 'has-success'">
...
But it doesn't work correctly. Can anyone help me?
I've found the solution. Here is my code:
<div class="form-group-sm has-feedback" ng-class="{ 'has-error' : myForm.Name.$invalid && !myForm.Name.$pristine && myForm.Name.$touched, 'has-success' : myForm.Name.$valid }">
...
</div>