我有一个form
元素:
<form name="formDate">
<input date-picker name="fundacao" ng-model-date="fTit.fundacao" required>
</form>
指令:
app.directive('datePicker', function(){
return {
restrict: 'A',
scope: {
ngModelDate: "=ngModelDate"
},
link: function (ng, el, attr) {
// $validators HERE
}
};
})
&#34; required&#34;验证不起作用,因为元素上没有ng-model
指令。
有没有办法验证带有非标准指令的表单,例如上面的示例?
答案 0 :(得分:0)
你可以在元素上绑定更改函数
app.directive('datePicker', function(){
return {
restrict: 'A',
scope: {
ngModelDate: "=ngModelDate"
},
link: function (ng, el, attr,ctrl) {
el.bind('change',function(){
//check the $(el).val();
var isValid= the date is valid;
ctrl.$setValidity('date',isValid);
// the first param is the validation key, the second param is true if valid false if invalid
})
}
};
})