How to resolve comma in input filter of boot tags?

I am using the code below to send tags using the bootstrap input tag filter, I want to allow a comma in the tags. Please, help.

$('.tagsinput').tagsinput({ maxTags: 15, trimValue: true, confirmKeys: [13], allowDuplicates: false, onTagExists: function(item, $tag) { alert('Tag already exists') $tag.hide.fadeIn(); } }); 
+7
twitter-bootstrap bootstrap-tags-input
source share
2 answers

Edit

Since the original recording time , there seem to be two options for this: delimiter and delimiterRegex . Therefore, you should be able to do .tagsinput({ delimiter: '|' }) or .tagsinput({ delimiterRegex: /\s+/ }) . The default is still,.

Original post

There is no possibility for this, so you have to change the code for the plugin. Line 87 bootstrap-tagsinput.js is split by ,. You can change this as another character, for example ; or | . If you want to make it more extensible, you can add splitOn: ',' to defaultOptions , and then change line 87 as var items = item.split(self.options.splitOn); . You can also add self.options.splitOn && to the if , which will prevent you from trying to split when there is nothing to share.

So, the code changes should look like this:

 // Line 4 var defaultOptions = { splitOn: ',' // ... }; // Line 86 if (self.options.splitOn && typeof item === "string" && this.$element[0].tagName === 'INPUT') { var items = item.split(self.options.splitOn); // ... } 

You need to continue to use confirmKeys: [ 13 ] and you probably want to use <select multiple></select> instead of <input /> so that you get an array instead of a comma separated line when you do $(".tagsinput").val();

Here is an example .

+7
source share

Add tags as objects instead of strings, for example:

 el.tagsinput({ itemValue: 'value', itemText: 'text', maxTags: 15, trimValue: false, //... }); el.tagsinput('add', { "value": 1 , "text": "Tag 1," }); el.tagsinput('add', { "value": 2 , "text": "Tag 2," }); //... 
0
source share

All Articles