Try this:
if (counter != -1) {
return true;
} else {
alert('This word is not in array');
$('.tagit-new input').val('');
return false;
}
Demo here
Pregunta
I use https://github.com/aehlke/tag-it this Addon for Autocomplete Tagging
The user just can take labels out of the existing array sampleTags
Before the tag is added I check whether the element is in 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 then is not deleted .
How can I do this?
jsFiddle: http://jsfiddle.net/zqDXL/3/
Solución
Try this:
if (counter != -1) {
return true;
} else {
alert('This word is not in array');
$('.tagit-new input').val('');
return false;
}
Demo here