AngularJS : Validating against multiple datepickers

2.3k Views Asked by At

Considering 3 dates : myDate1, myDate2, myDate3. I'd like to validate that myDate1 < myDate2 < myDate3

Dates are set by the date picker directive found in angular-ui.

Here is a plunker : http://plnkr.co/edit/FTcJNHxuv3RFtBCUw7Ck

I'm having difficulties founding the right way to do that. I'm using ui-validate but it looks like when a condition is evaluated to false, the model is set to undefined.

Edit : It turns out that model being set to undefined is normal Angular behaviour. However there is a bug in the ui-validate directive. I'll update this post once it's resolved. See : https://github.com/angular-ui/ui-utils/issues/25

1

There are 1 best solutions below

1
Rajkamal Subramanian On

Please have a look at this fiddle. http://plnkr.co/edit/p0cq1idV6xTF2LyorQ06?p=preview.

Instead of using ui-validate i used ng-change and an extra scope variable formValid to track the validity of form.