ui-select icon indicating copy to clipboard operation
ui-select copied to clipboard

ng-required not validating form on submit

Open mouryaamit opened this issue 12 years ago • 82 comments

when using ui-select with ng-required or required attribute, form is not validating on submit action.

mouryaamit avatar Oct 05 '14 02:10 mouryaamit

I'm also finding this issue. For me, it only occurs if the input is multi select

example: http://plnkr.co/edit/38ZVblng7d6B34DIGTIw?p=preview

howieweiner avatar Oct 08 '14 23:10 howieweiner

Same issue here... validation on multiselect doesn't work

LeleDev avatar Nov 05 '14 12:11 LeleDev

+1

line-o avatar Nov 26 '14 12:11 line-o

+1

cgwyllie avatar Nov 26 '14 13:11 cgwyllie

Thanks for this fix.. but still i can see one more issue. this ng required validation work first time perfectlly but once first select and then remove the element then ng-required validation didn't worked. can you please test this scenario as well.

  1. without selecting any thing ng-required work fine
  2. select few element
  3. removed all element from drop down
  4. you see ng-required is not working any more now.

sandeep-goyal avatar Nov 28 '14 18:11 sandeep-goyal

+1

ericklombardo avatar Dec 17 '14 18:12 ericklombardo

+1 what are people doing to validate this thing in the meantime?

mkoryak avatar Dec 17 '14 19:12 mkoryak

I write a custom directive for override the $isEmpty function for ngController, like this:

angular.module('myModule).directive('uiSelectRequired', function () {
    return {
        restrict: 'A',
        require: 'ngModel',
        link: function (scope, element, attrs, ngModelCtrl) {
            if (angular.isUndefined(attrs.multiple)) {
                 return;
            }
            ngModelCtrl.$isEmpty = function (modelValue) {
                return !modelValue.length;
            };
        }
    };
});

and its works; just have to include this directive along with ngRequired

ericklombardo avatar Dec 17 '14 20:12 ericklombardo

i tried but its giving me error can you please include some plunker so i will have implement in the same way. many Thanks for the help

sandeep-goyal avatar Dec 17 '14 20:12 sandeep-goyal

i found the issue if your all element is selected default in modal it will not work. It will work only once you select and remove any element. so for that i have put the fix in your custome directive.

ngModelCtrl.$isEmpty = function (modelValue) { if(modelValue.length<1) return !modelValue.length; };

sandeep-goyal avatar Dec 17 '14 21:12 sandeep-goyal

Actually there is a much better workaround. Just use ui-validate

<ui-select multiple ui-validate="{required: 'validateRolesRequired($value)', admin: 'validateRolesAdmin($value)'}">

then in controller

$scope.validateRolesRequired = (value)->
    !_.isEmpty(value)

  $scope.validateRolesAdmin = (value)->
    false

marigan avatar Dec 22 '14 21:12 marigan

@RichardAllen Has your fix been merged?

Also, I added this code to my own project and it appears to have no effect.

abobwhite avatar Jan 27 '15 17:01 abobwhite

+1

ravishivt avatar Jan 30 '15 22:01 ravishivt

+1

noetix avatar Feb 05 '15 22:02 noetix

+1

vtortola avatar Feb 09 '15 15:02 vtortola

+1

olso avatar Feb 12 '15 10:02 olso

+1

eliias avatar Feb 12 '15 21:02 eliias

+1 (the patch is working fine by the way, but not all the times as reported above)

sofiageo avatar Feb 18 '15 10:02 sofiageo

Multiselect validation doesn't work in 0.9.9

dmitrygaraev avatar Feb 18 '15 18:02 dmitrygaraev

Not working for me either with ui-select 0.9.9 and angular 1.3.11

yaneq avatar Feb 20 '15 10:02 yaneq