0

I have form with input fields. The classes which are applied to input field are changed on click of submit button. I want to apply css rule if two css classes are applied with other css classes

Ex.

<input ng-model="formField.val" type="text" name="103" 
       class="form-control ng-pristine ng-untouched ng-empty ng-invalid ng-invalid-required" 
       ng-disabled="readOnlyFlag" required="">

on click of submit button, the new css classes ng-invalid & ng-touched are applied with other css classes. I want apply css rule if ng-invalid & ng-touched are applied with other css classes.

 <input ng-model="formField.val" type="text" name="103" 
       class="form-control ng-pristine ng-empty ng-invalid ng-invalid-required ng-touched ng-invalid ng-invalid-required" 
       ng-disabled="readOnlyFlag" required="">
dnyanesh
  • 101
  • 1
  • 6

1 Answers1

2

Add styling for input when it has two classes:

input.ng-invalid.ng-touched{
  background:red;
  color:red;
}

Or if you want to use code use hasClass :

angular.element(myElement).hasClass('my-class');
angular.element(myElement).addClass('new-class');
angular.element(myElement).removeClass('old-class');

Code is copied from this question.

Community
  • 1
  • 1
Ralf de Kleine
  • 11,464
  • 5
  • 45
  • 87