我正在尝试使用选项多选项来验证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;
};
}
};
});
这总是返回无效。
如果验证器返回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;
};
}
};
});