質問

Im wondering is there any way to make some actions after the plugin is applied For example,

$("#mytags").tagit({
    tagSource: function (request, response) {




    }
});

and I want smth like this:

$("#mytags").tagit({
    tagSource: function (request, response) {




    }
}, function(){
        $(#test).remove();
});
役に立ちましたか?

解決

I took a good look in the source code of the plugin and it doesn't provide such callback. I need it as you. In my case, it doesn't import the required attribute, so the required message appears floating completely lost on the page. I made a monkey patch. It's not perfect, but solved my case. I'll try to add this callback to tag-it and send it to github. Anyway, here is my dirty fix:

       var temp = setInterval(function()
       {
            if( $('.ui-widget-content.ui-autocomplete-input').length > 0 )
            {
                clearInterval(temp);
                $('.ui-widget-content.ui-autocomplete-input').doSomething();
            }
       }, 500);


EDIT: Better solution. As I've just said. I made an alteration in the code and I'm sending it to the main branch, you can see my version of the plugin here: https://github.com/kalkehcoisa/tag-it/blob/master/js/tag-it.js It has a callBack "afterCreated" that is fired when the tagit finishes being applied. One example of how to use it:

            $('#singleFieldTags').tagit({
            availableTags: sampleTags,
            singleFieldNode: $('#mySingleField'),
    afterCreated: function(){ alert( 'test' ); },
        });


I hope this helps. ;)

Hey! The tag-it head developer answered me (https://github.com/aehlke/tag-it/pull/215#issuecomment-26191461) about my pull request. The thing were far simpler than we thought:

All you need is $('#myWidget').('create', function (event) { /* ... */ }); as is standard in jQuery UI. Perhaps an example in the docs is necessary...

Developing and learning! ;P

他のヒント

You need to discover plugin API for appropriate event. If you use this one, it has such event: afterTagAdded (function, Callback).

Read documentation for how to use.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top