-
-
Save fazlurr/8ca1e94f3de8bb948365a212bd9d10cc to your computer and use it in GitHub Desktop.
select2 Tagging Support how to dynamically add tag from JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // open http://ivaynberg.github.io/select2/ | |
| // go down to "Tagging Support" | |
| // #s2id_e12 is a DIV wrapping the whole tagging input | |
| // enter value -> make it think it's pasted on -> fire ENTER key | |
| target = $("#s2id_e12 ul input.select2-input"); // this will fetch input tag | |
| target.val(new Date().getTime()); // type in whatever you want | |
| target.trigger("paste"); // this even is the key to tag dynamically | |
| event = $.Event('keydown'); | |
| event.which = 13; // this will fire up ENTER key event | |
| target.trigger(event); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
