I am using a directive to validate two form fields (dates) in angularjs (version 1.0.2). In order to validate the form I use the following directive.
http://jsfiddle.net/cafau/Ja2ar/
The only change I made is to rename the directive to ui-validate.
I have created a fiddle at
http://jsfiddle.net/sidkurias/xXf6b/
I have included part of the html I am using and relevant parts of the controller.
There are two methods on the controller validStartDate and startBeforeEnd that I would like to invoke from the directive. When I do so I get the following error
Error: Syntax Error: Token '{' is unexpected, expecting [)] at column 13 of the expression [(function (){
var sdate = new Date($scope.avail.sdate),
today = new Date(getDefaultDates(0));
return sdate >= today ;
}) && true] starting at [{
var sdate = new Date($scope.avail.sdate),
today = new Date(getDefaultDates(0));
return sdate >= today ;
}) && true].at Error (<anonymous>)
at throwError (http://g.dev/app/lib/angular/angular.js:5867:11)
at consume (http://g.dev/app/lib/angular/angular.js:5905:7)
at primary (http://g.dev/app/lib/angular/angular.js:6075:7)
at unary (http://g.dev/app/lib/angular/angular.js:6066:14)
at multiplicative (http://g.dev/app/lib/angular/angular.js:6049:16)
at additive (http://g.dev/app/lib/angular/angular.js:6040:16)
at relational (http://g.dev/app/lib/angular/angular.js:6031:16)
at equality (http://g.dev/app/lib/angular/angular.js:6022:16)
at logicalAND (http://g.dev/app/lib/angular/angular.js:6013:16)
<form name="availForm" ui-validate="{startDate: validStartDate, sbe:startBeforeEnd}" class="ng-pristine ng-valid"> <br>
The call to the watch function resolves the validation functions correctly, but then it throws the above syntax error. Any ideas as to why angular does not like the function definitions. Thank you
It seems you need to place quotes ('') around your functions:
ui-validate="{startDate: 'validStartDate()', sbe:'startBeforeEnd()'}"