Я хочу включить проверку на определенные поля. Проверка должна показывать сообщения только тогда, когда установлен флажок. Я пытаюсь добиться этого в Angular
form.cshtml
<input type ="checkbox" ng-click = "mainControl.reportUpdates()">
<input type = "text" date-validator = "type.date">
<ul messages = "mainform['date'+$index].$error">
<li ng-message="required"> Required</li>
<li ng-message = "maxdatevalidator">Date cannot be greater than today
</li>
<ul>
App.js
_module.directive('dateValidator', ['$rootScope','$parse',function($rootscope,$parse)])
{
function maxDate(date)
{
var today = new Date();
if(date!=null)
return date>today
else
return true
}
return
{
require: 'ngModel',
link : function(scope,element,attrs,ctrl)
{
scope.$watch(attrs.ngModel,function(newValue,oldValue))
{
if(newValue!=oldValue)
{
var check_date=maxDate(newValue)
ctrl.setValidity('maxdatevalidator',check_date) ;
}
}
}
}
}