Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue while loading taggit function after an ajax request #34

Closed
nandakumar444 opened this issue Sep 23, 2011 · 2 comments
Closed

Issue while loading taggit function after an ajax request #34

nandakumar444 opened this issue Sep 23, 2011 · 2 comments

Comments

@nandakumar444
Copy link

Hi,
I am using the plugin to load the tags to a text box. The tags will be retrieved from an Ajax request which will be called onload. The plugin will work properly if i attach the tagit function to the element before the ajax request. But if i try to set the available tags from the ajax request response there will be an error "$("#tag").tagit is not a function" .

the code is like this

$(function()
{
setTags();
});

function setTags()
{
$(":input").each(function(index) {
var elementId = '#'+(this.id);
var tagAttribute = $(elementId).attr('tag');
if(typeof tagAttribute !== 'undefined' && tagAttribute !== false)
{
var data = {};
var url = absoluteurl+'/tags.php';
data['tg'] = tagAttribute;

        //response = ['PHP','MYSQL','JAVA','JAVASCRIPT'];
        $.post(url,data,function(response)
        {
        setTagResponses(response, elementId);
         },'json');

    }
});

}

function setTagResponses(tags, elementId)
{
if(tags.length > 0)
{
$(elementId).tagit({
availableTags: tags
});
}
}

@tjarratt
Copy link
Contributor

What if instead of passing the id for the element, you pass the element itself?

This looks pretty easy to debug if you set a break point inside setTagResponses and look at what you get with $(elementId) -- you might be passing in some value you didn't expect.

@aehlke
Copy link
Owner

aehlke commented Nov 25, 2012

Closing this since it doesn't seem to be a bug with tag-it - LMK if it is or if you're still having trouble, thanks.

@aehlke aehlke closed this as completed Nov 25, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants