Reputation: 3327
I'm trying to make a form validation using angularjs. I could manage it anyway. Now, I'm trying to add a red border at input box when it's invalid. I can do this by adding this css:
/*Show red border if kept the input empty after touching*/
.ng-touched.ng-invalid-required {
border-color: red;
}
/* Show red border when stuff has been typed in, but its invalid */
.ng-dirty.ng-invalid {
border-color: red;
}
/*Show normal border color when typed in for the first time*/
.ng-untouched.ng-invalid {
border-color: #ccc;
}
But, at the first time if any input box is empty and untouched and at that time if anybody click 'Submit' button, it'll show error message but it don't show any red border:
I don't understand which class I should define in CSS for this scenario. How can I make the input box red bordered if anybody click the 'Submit' button keeping input box empty and untouched?
Upvotes: 3
Views: 16045
Reputation: 136144
Use nested class inside your css using ng-submitted
/*Show red border if kept the input empty after touching*/
.ng-touched.ng-invalid-required {
border-color: red;
}
/* Show red border when stuff has been typed in, but its invalid */
.ng-dirty.ng-invalid {
border-color: red;
}
/*Show normal border color when typed in for the first time*/
.ng-untouched.ng-invalid {
border-color: #ccc;
}
.ng-submitted input.ng-invalid{
border-color: red;
}
Hope this could help you. Thanks.
Upvotes: 4