Frage

I'm using tagit (http://webspirited.com/tagit/) and really liking it so far. I've just got one snag to overcome. If I start typing a tag keyword, change my mind then click elsewhere on the page (so the input loses focus), the tag gets added. I dont want this to happen. I want the tag to only be added when the trigger key has been selected - in my case the comma. Otherwise the last tag (probably partial text) should just sit there until a comma is added.

This is the code I have so far. Pretty basic implementation, but I dont see a way to prevent the scenario above.

 $('#thename').tagit({
      tagSource:, 
      select:true,
      tagsChanged:function (a, b) {
         if(b=='added' || b=='popped'){
            submitForm();
         }
       },
      triggerKeys:new Array('comma')
   });
War es hilfreich?

Lösung

Made a little hack for this one, we'll see how it turns out. I couldn't find anywhere in the API to not add the tag on focus out, so my next solution was to do the following:

-Type a tag
-Click out of the input (so the tag gets added)
-Programatically get the text input and remove the tag

Attempted this with the following code:

$("#thename").focusout(function() {
    //Get the input text
    var tagText = $(this).val();

    //Verify input is NOT empty

    //Remove the tag that was just added
    $("#thename").tagit('removeTag', tagText);

});

Let me know how this works.

Edit:

Just noticed your comment up there. If you don't want to allow new tags, then add the

allowNewTags: false,

To your tagit markup in the original code.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top