1

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();
});
Leg0
  • 510
  • 9
  • 21
  • Can you provide more of your `tagSource` function? – Ian Dec 05 '12 at 14:46
  • tagSource function doesnt matter at all It can be any function, I dont need a callback from tagSource func, I need callback for the successfully applied plugin – Leg0 Dec 06 '12 at 09:26
  • Why do you need a callback? Why can't you just call `$("#test").remove();` on the next line? – Ian Dec 06 '12 at 14:05
  • If you really need it in a chained manner (even though in your example it's only selecting one element), you could use `$("#mytags").tagit({}).each(function () { // Refer to 'this' for each element });` – Ian Dec 06 '12 at 14:11
  • I need a callback because: tagIt transforms my div into tagIt block with input, I need to put a placeholder value on input, but I can do it only after successful plugin init – Leg0 Dec 06 '12 at 18:58
  • So my point is: is there anything asynchronous being done in `tagSource`? Like, is it making an AJAX call or something? If not, then there's no reason you can't just call `.remove()` on the next line. – Ian Dec 06 '12 at 19:20
  • Do either of these help? http://stackoverflow.com/questions/6938802/trying-to-get-tag-it-to-work-with-an-ajax-call or https://github.com/aehlke/tag-it/issues/13 . Like I said before, your code for your `tagSource` method would help, but hopefully those links can help – Ian Dec 07 '12 at 00:58
  • the thing is that tagSource success func is called when some actions are provided and I need to do smth exactly after plugin is applied, no any other actions performed and there's just no native success callback for jquery plugins from what I see. – Leg0 Dec 07 '12 at 20:11

2 Answers2

1

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

Jayme Tosi Neto
  • 1,189
  • 2
  • 19
  • 41
  • Hi @Jayme. Nicely explained answer. I am getting an error when i try $('#myWidget').('create',function(){ alert("in"); }); is giving me an error "Unexpected token (" – Hbksagar Nov 27 '14 at 11:02
  • Added create function inside the widget itself. Started working as expected. Thank you for the answer. – Hbksagar Nov 27 '14 at 12:31
-2

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.

pxx
  • 259
  • 1
  • 8
  • Thanks, but thats not what I need. Exactly what I need is: 1. Plugin applies to the div, sends whatever etc 2. After its done I need to hide/remove/do anythings else. Is that possible? – Leg0 Dec 05 '12 at 18:15