-
Notifications
You must be signed in to change notification settings - Fork 1.8k
ng-required not validating form on submit #258
Comments
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 similar comment
+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.
|
+1 |
+1 |
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) { |
Actually there is a much better workaround. Just use ui-validate
then in controller
|
@richardallen Has your fix been merged? Also, I added this code to my own project and it appears to have no effect. |
+1 |
4 similar comments
+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 |
I fixed it now by adding a custom validator for the multiple ui-select module.directive('uiSelectRequired', function() {
return {
require: 'ngModel',
link: function(scope, elm, attrs, ctrl) {
ctrl.$validators.uiSelectRequired = function(modelValue, viewValue) {
return modelValue && modelValue.length;
};
}
};
}); // in view
ui-select {
multiple='true'
ng-model='something.something'
ui-select-required
} |
@yaneq solution almost works for me. The condition Here's the code app.module.directive('uiSelectRequired', function() {
return {
require: 'ngModel',
link: function(scope, elm, attrs, ctrl) {
ctrl.$validators.uiSelectRequired = function(modelValue, viewValue) {
var determineVal;
if (angular.isArray(modelValue)) {
determineVal = modelValue;
} else if (angular.isArray(viewValue)) {
determineVal = viewValue;
} else {
return false;
}
return determineVal.length > 0;
};
}
};
}); This is my markup <ui-select name="items" multiple
ui-select-required
ng-model="item.items">
<ui-select-match>
{{$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> And the items list is an array of objects. [
{id: 1, name: 'item 1'},
{id: 2, name: 'item 2'},
...
] Anyone care to explain why |
@zentetsukenz why not use the patch from cc49678 ? |
@gsf-greece I try version 0.11.1 and still not working so I go back to version 0.9.9, because, initially, my project use 0.9.9, then use the method posted above and finally got it works. Not sure why cc49678 wasn't fixed for me. Thanks for your suggestion :) |
Just an update, 0.11.2 fixes most of the problems I had encountered, so with the patch mentioned above ui-select seems to be working great. Let's hope it will be merged soon! thanks for your great work so far. |
Can patch cc49678 be merged to latest? It fixes this issue for me. |
Anyone else having an issue with the validation kicking in before user interaction (after applying patch cc49678) ? I don't see any use of |
+1 |
+1 @mukulgupta2507 Great job, thank you! |
+1 |
to support expression evaluation I am using this:
|
This worked for me: .directive('arrayRequired',function(){
return {
restrict:'A',
require:'ngModel',
link:function(scope,elem,attrs,ngModel){
ngModel.$validators.arrayRequired = function(modelValue,viewValue){
var modelValue = modelValue || {}
return (modelValue.length>0 ? true : false);
};
}
};
}) add |
@stkrwilson |
|
Hello guys!, I've solved this to use in one of our projects, you can find the library working here: https://github.com/zgbjgg/ui-select/tree/ng-required Basically, I did a change to observe the ng-required, and change to false when the model is not empty, otherwise is required (set to true), I hope this can be helpful :) |
@zgbjgg Can you point us to the changes you made? |
@randdusing follow his link, check the commit log, view his commit. |
@zgbjgg Ah you modified |
@zgbjgg I cleaned up your commit and made it into a PR, hope you don't mind. I really need this to work ;) |
@zgbjgg hm I just tested your changes and they don't work for me. |
I had to the template an hidden input who display the placeholder. Here my commit : I don't have time to realy test this new functionality and create a PR. |
Hello, I am not expert building with the tools provided by gulp for example, but, for a project, I helped to my team to make this work, and using with the code that I modified seems to work perfectly and the ng-required is validated correctly when a form is submitted! |
I've just added two conditions more. Now I can use it in single selects.
|
Hey Guys, could simplify this like this, using lodash:
Might be missing something but it seems you wouldnt want to check on the viewValue unless, maybe, you were allowing someone to dynamically add tags, no? |
+1 |
+100 and thanks @doug31415 |
Please do not "+1" issues, use github 👍 reactions if you really must. Comments should be reserved for constructive discussion/issue resolution. +1s merely add unnecessary noise and scrolling between other, more helpful, replies. Other ways you can actually help include: Submitting a pull request that resolves the issue/adds the requested feature Thanks! 😄 |
Hi Jeffrey
Actually in our group we use the +1 to indicate a passing review, so its more than just noise. Is there some issue with our doing that on our own teams?
Doug
From: Fourth floor <[email protected]<mailto:[email protected]>>
Reply-To: angular-ui/ui-select <[email protected]<mailto:[email protected]>>
Date: Thursday, March 9, 2017 at 1:53 PM
To: angular-ui/ui-select <[email protected]<mailto:[email protected]>>
Cc: Doug Goodman <[email protected]<mailto:[email protected]>>, Mention <[email protected]<mailto:[email protected]>>
Subject: Re: [angular-ui/ui-select] ng-required not validating form on submit (#258)
Please do not "+1" issues, use github 👍 reactions if you really must. Comments should be reserved for constructive discussion/issue resolution. +1s merely add unnecessary noise and scrolling between other, more helpful, replies.
Other ways you can actually help include:
Submitting a pull request that resolves the issue/adds the requested feature
Researching possible implementations or causes of bugs
Providing reproduction plunkrs if one isn't already available
Thanks! 😄
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#258 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AI0n6QczgLiksarMPpHy9ONFfZf2Jsz1ks5rkEqOgaJpZM4Cq5Is>.
|
Don't know here it is preferred to do it in the way as described. |
Works fine for me... |
I'm going to close this issue. As this issue is present a long time I think it is best to create a new one when people want to address this again. Hope you all agree if not let me know I will reopen it. 😺 |
when using ui-select with ng-required or required attribute, form is not validating on submit action.
The text was updated successfully, but these errors were encountered: