drewwyatt drewwyatt - 1 year ago 91
Javascript Question

Can Angular add a css class to a parent/sibling element when input is invalid

My form elements look like this:

<div class="control-group">
<label for="email">Email Address</label>
<input type="email" class="form-control" name="email" ng-model="message.emailAddress" id="email" />

Angular automatically adds the class "ng-invalid" to the input when the email address is invalid - but I would also like it to add a class the label or the control-group.

Is that possible? or is there an easy workaround?

Answer Source

Classes are added to the parent form element labeled as ng-invalid-inputName. You could style off of this.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download