max-favilli / tagmanager

A jQuery plugin (working nicely with twitter bootstrap)
Mozilla Public License 2.0
770 stars 236 forks source link

The newTagRemoveId onClick handler is not attached #112

Closed MaartenW closed 11 years ago

MaartenW commented 11 years ago

Don't know why but the spliceTag method is not attached to the onClick event. However, after simplifying the following:

$el.find("#" + newTagRemoveId).on("click", obj, function (e) {
  e.preventDefault();
  var TagIdToRemove = parseInt($(this).attr("TagIdToRemove"));
  spliceTag(TagIdToRemove, e.data);
});

To this: (replace find with regular selector and remove obj from event binder)

$("#" + newTagRemoveId).on("click", function (e) {
    e.preventDefault();
    var TagIdToRemove = parseInt($(this).attr("TagIdToRemove"));
    spliceTag(TagIdToRemove, e.data);
});

Everything works dandy.

johnnyshields commented 11 years ago

@MaartenW I just tested the current version and I see spliceTag() being called as expected in the current version. Can you please create a JS Fiddle which reproduces your issue?

We changed this to use $el.find() from a PR raised by @kenshin (ee4c607b47c6630e4523f1739354cf69be1d7503) related to errors happening if TagManager initializes before the DOM tree.

MaartenW commented 11 years ago

Hi Johnny, I can't seem to reproduce the error in JSFiddle so I'm sure it's on my side. Sorry I did not JSFiddle it before creating an issue here.

MaartenW commented 11 years ago

I now notice it actually has to do with the way one initializes tagManager. If tagManager is initiated using the .each method like this: (http://jsfiddle.net/gS9nV/3/)

$(document).ready(function(){

    // Enable tagbox
    $(".tm-input").each(function(){
        $(this).tagsManager({
            prefilled:$(this).val().split(','),
            typeahead: true,
            typeaheadSource: ["Gouden Kalf", "Cannes Palm", "Gouden Framboos", "Emmy Award", "Academy Award", "Tony Award", "Rembrandt Award", "Student Award","EFA Young Audience Award"
            , "Vimeo Award", "Hivos Tiger Award", "IFFR Award", "BAFTA Award", "NFF Award", "Eurobest Award", "Nederlandse Academy Award", "Beeld en Geluid Award", "European Film Award",
            "Joris Ivens Award"],
            onlyTagList: true
        });
    })

});

Tags close as they should. But initialized like this (directly, without the .each method): (http://jsfiddle.net/gS9nV/2/)

$(document).ready(function(){

    // Enable tagbox
    $(".tm-input").tagsManager({
            prefilled:$(this).val().split(','),
            typeahead: true,
            typeaheadSource: ["Gouden Kalf", "Cannes Palm", "Gouden Framboos", "Emmy Award", "Academy Award", "Tony Award", "Rembrandt Award", "Student Award","EFA Young Audience Award"
            , "Vimeo Award", "Hivos Tiger Award", "IFFR Award", "BAFTA Award", "NFF Award", "Eurobest Award", "Nederlandse Academy Award", "Beeld en Geluid Award", "European Film Award",
            "Joris Ivens Award"],
            onlyTagList: true
    })

});

tags appear on every tm-input and the close button doesn't work anymore. I'll search for a similar issue before opening a new one.