-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding dynamic tags does not work #3655
Comments
http://stackoverflow.com/q/29058625/359284
Yes, this is because the option that you are trying to set the value to does not actually exist. |
Thanks for the link, but I already used an equivalent solution. I rephrase my previous question: why are we forced to add manually the option? If the tags are activated, the update of Select2 should automatically create this option. |
It's important to note that the
We are forced to manually add the option because jQuery will not automatically create it for you. We did the equivalent of this in the past with |
It's obvious that we should not override the Indeed, in this case, my proposal is not possible. But perhaps it would be easier and faster to have an helper for add a new tag directly in JS, because the implementation already exists (creating the option with the good attributes,etc...). Thank you for your great component. |
When I manually add an option to the select, I need to include a custom data attribute. How is that done? When I use AJAX to get the items, this works fine:
But I need to load these results back into the select2 as tags upon load and I can't get the extra data property (company) added:
|
@clockwiseq please open this as a new issue. |
Hello @kevin-brown,
what was the implicit part of it ? may be the naming was not correctly? the previous function created the option while jquery one does not maybe we should call it addOption or something more meaningful to it, we could keep setting value as it is right now with jquery and you add a new method for appending options. |
In my case, i'm using select2 v3.4.5. All I had to write,
here |
For
4.0
branch.When you use the methods
val(<data>)
orselect2('val', <data>)
with the optionsmultiple=true
andtags=true
, The selection displayed contains only the values of the existing select options, without including the new tags.HTML:
JS:
However, if you created a new tag via the dropdown, and that you delete this tag, The
.val()
method does work (because theoption
still exists in theselect
).Is it normal that the
val
method does not create theoption
in theselect
?The text was updated successfully, but these errors were encountered: