ng-required not validating form on submit
when using ui-select with ng-required or required attribute, form is not validating on submit action.
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
Same issue here... validation on multiselect doesn't work
+1
+1
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.
- without selecting any thing ng-required work fine
- select few element
- removed all element from drop down
- you see ng-required is not working any more now.
+1
+1 what are people doing to validate this thing in the meantime?
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
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
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; };
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
@RichardAllen Has your fix been merged?
Also, I added this code to my own project and it appears to have no effect.
+1
+1
+1
+1
+1
+1 (the patch is working fine by the way, but not all the times as reported above)
Multiselect validation doesn't work in 0.9.9
Not working for me either with ui-select 0.9.9 and angular 1.3.11