4

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/

Rikard
  • 7,485
  • 11
  • 55
  • 92
Susanne92
  • 217
  • 1
  • 6
  • 21
  • Can you explain more which input should be deleted and when? btw, geige is not there :) – Sergio Aug 31 '13 at 11:34
  • :) ! e.g. if you type in 'Klav' you can choose 'Klavier'. But when you type in 'klaw' and you press enter the alert opens up, but 'klaw' is not deleted! – Susanne92 Aug 31 '13 at 11:39

1 Answers1

2

Try this:

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

Demo here

Sergio
  • 28,539
  • 11
  • 85
  • 132