Delete tagLabel in input field with tagit tag

I use https://github.com/aehlke/tag-it this add-on for autocomplete tags

User can simply take tags from an existing array of sampleTags

Before adding a tag, I check if the element is in the array or not

beforeTagAdded: function(evt, ui) { var counter = jQuery.inArray(ui.tagLabel, sampleTags); if (counter != -1 ) { return true; } else { alert('This word is not in array'); return false; } }, 

But the input is not deleted.

How can i do this?

jsFiddle: http://jsfiddle.net/zqDXL/3/

+4
source share
1 answer

Try the following:

 if (counter != -1) { return true; } else { alert('This word is not in array'); $('.tagit-new input').val(''); return false; } 

Demo here

+2
source

Source: https://habr.com/ru/post/1499916/


All Articles