No validation does not work when adding multiple

52 Views Asked by At

I am trying to do the validation of ui-select with the option multiple option. But no angular validation works. Even creating a custom validation. That always returns invalid.

Only remove the (multiple) option that all validations work (required and customized)

<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

1

There are 1 best solutions below

3
georgeawg On

That always returns invalid.

It works better if the validator returns 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;
            };
        }
    };
});