-
Notifications
You must be signed in to change notification settings - Fork 1.8k
required tag #850
Comments
Are you using |
I have tried both with no success. Any idea what I could be doing wrong here?
|
Nothing jumps out at me, though I have no what might conflict with the validation. Maybe the disabled state? Here's my code for reference. When the drop down is an empty value, the field container is properly marked as
|
I'm still having issues. Going to try to break it down using the examples. |
I stripped down the demo.html example and gave this a shot. The input prompts holds true for the required tag but the select does not.
I am at a loss on this. Any ideas what could be going on? Am I not setting the form and submit up properly or is this a bug? |
this works on the button for submission but what I do not get is the UI prompt stating not all fields have been filled out.
|
+1 on this. Would be great to be able to do
|
Sounds like use of |
+1 on this |
+1 |
1 similar comment
+1 |
Just a note, the required validation won't work with basic HTML5 validation. You need to add |
I just submitted a PR to fix the issue with However, as with all of the UI-Select elements you'll need to check for the PR Link: #1025 |
It looks like the required attribute is not being copied across from original hidden input to the generated one... <div class="controls">
<div class="select2-container ng-pristine ng-untouched ng-invalid ng-invalid-required" id="s2id_newCommunity_country_id" style="min-width: 220px; margin-bottom: 0px;">
<a href="javascript:void(0)" class="select2-choice select2-default" tabindex="-1"> <span class="select2-chosen" id="select2-chosen-1">Select country...</span><abbr class="select2-search-choice-close"></abbr> <span class="select2-arrow" role="presentation"><b role="presentation"></b></span>
</a>
<label for="s2id_autogen1" class="select2-offscreen">Country</label>
<input class="select2-focusser select2-offscreen" type="text" aria-haspopup="true" role="button" aria-labelledby="select2-chosen-1" id="s2id_autogen1">
<div class="select2-drop select2-display-none select2-with-searchbox">
<div class="select2-search">
<label for="s2id_autogen1_search" class="select2-offscreen">Country</label>
<input type="text" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" class="select2-input" role="combobox" aria-expanded="true" aria-autocomplete="list" aria-owns="select2-results-1" id="s2id_autogen1_search" placeholder=""> </div>
<ul class="select2-results" role="listbox" id="select2-results-1"> </ul>
</div>
</div>
<input type="hidden" id="newCommunity_country_id" name="newCommunity.country.id" value="" ui-select2="countrySelect2Options" ng-model="results.country" data-placeholder="Select country..." ng-required="true" style="min-width: 220px; margin-bottom: 0px; display: none;" required="required" class="ng-pristine ng-untouched ng-invalid ng-invalid-required" tabindex="-1" title="Country">
</div> If I modify the generated input field and add the required attribute then the html5 validation fires as expected and displays the standard error message: I don't think this is necessarily a select2 issue because they seem to have it working except for the positioning issue mentioned in issue select2/select2#128 |
@tazmaniax did u manage to find how to fix required validation for ui-select to show this html5 validation popup ? |
@f1ght4fun unfortunately I haven't had any more time to look into it and I'm just living with the issue at the moment which is not great. |
I did throw in a PR for making it worked with multiple. The only catch is that it only works with angular validation (via the Form) and wont get caught by basic validation. But really, serious UX apps need better validation anyway since the basic |
The required/ngRequired directive doesn't actually check if the value is empty; it calls $isEmpty, which is meant to be overridden by directive (in this case uiSelect). Rather than try to reinvent the required directive, just override this method. Here's what I settled on: module.directive('uiSelect', function() {
return {
restrict: 'EA',
require: '?ngModel',
link: function (scope, element, attrs, ctrl) {
if (ctrl && angular.isDefined(attrs.multiple)) {
ctrl.$isEmpty = function(value) {
return !value || value.length === 0;
};
}
}
};
}); |
+1 for
|
Any progress on this? A workaround would be to create another input that is not displayed <input type="text" style="display: none" name="vendor" ng-model="item.vendorId" required/> |
+1 for |
I'm trying to use @kmccullough your solution is working and it's much better than the hack that @andidev proposed, why not adding it to the code of ui-select? |
@kmccullough proposal worked. Is this something we will see in the upcoming releases? |
fix(uiSelectMultipleDirective): add $isEmpty handler Fixes #850
Is it possible to set a required tag for this control? I am not getting a prompt when the required tag is set and it is embedded in a form element. Thanks.
The text was updated successfully, but these errors were encountered: