我正在尝试使用选项多个选项对ui-select进行验证。但是没有角度验证有效。甚至创建自定义验证。这始终返回无效。
仅删除所有验证都有效的(多个(选项(必需和自定义(
<ui-select multiple ng-model="Model.Test" close-on-select="false"
search-enabled="true" required custom-validation>
<ui-select-match allow-clear="true">{{$item.Name}}</ui-select-match>
<ui-select-choices repeat="item in Items | filter:$select.search">
<div ng-bind-html="item.Name | highlight: $select.search"></div>
</ui-select-choices>
</ui-select>
app.directive('customValidation', function () {
return {
require: 'ngModel',
link: function (scope, elm, attrs, ctrl) {
ctrl.$validators.customValidation = function (modelValue, viewValue) {
return false;
};
}
};
});
https://codepen.io/anon/pen/BEboLq
这始终返回无效。
如果验证器返回true
,效果会更好:
app.directive('customValidation', function () {
return {
require: 'ngModel',
link: function (scope, elm, attrs, ctrl) {
ctrl.$validators.customValidation = function (modelValue, viewValue) {
̶r̶e̶t̶u̶r̶n̶ ̶f̶a̶l̶s̶e̶;̶
return true;
};
}
};
});