JARRRRG
JARRRRG

Reputation: 926

Configure angularjs to set ng-invalid on a form control based on an expression

I have 2 form controls.

html

<input name="password"
       required
       type="password"
       ng-model="form.password" />

<input name="confirmPassword"
       required
       type="password"
       custom-validator
       ng-model="form.confirmPassword" />

Currently they work independently and in the scenario where password is invalid, angularjs still (rightly so) sets the confirmPassword input's class to ng-invalid if the confirmPassword control's input is invalid.

I need to be able to add a conditional somewhere, so that the 'ng-invalid' class only gets set IF the first control is $valid (form.password.$valid).

Upvotes: 0

Views: 1433

Answers (1)

Aaron
Aaron

Reputation: 24802

You will want to use a custom $validator directive as documented in angularjs' developer guide.

Upvotes: 1

Related Questions