Mahnoor Fatima Baloch
Mahnoor Fatima Baloch

Reputation: 21

How to I avoid Jquery tags input Cannot read property 'split' of undefined error

I am trying to add tags input.My code is as follow

if($('#tags_tagsinput').length == 0) {
        $('#tags').tagsInput({
            autocomplete_url: App.routes.social.tags.search(bootstrapFacility.id).fullRoute(),
            width: '100%',
            height: '35px',
            placeholderColor : '#666666',
            defaultText: '',
            caseInsensitiveUnique: true
        });
        $('#tags').importTags($('#tags').val());
    } else {
        $('#tags').importTags($('#tags').val());
    }

This code works fine but randomly it throws error.Page will keep loading and following error will be shown on console:

Uncaught TypeError: Cannot read property 'split' of undefined
at Function.t.fn.tagsInput.importTags (social_vendor.js:1)
at f.fn.init.t.fn.importTags (social_vendor.js:1)
at HTMLDocument.eval (eval at globalEval (social_vendor.js:1), <anonymous>:45:15)
at u (social_vendor.js:1)
at Object.add [as done] (social_vendor.js:1)
at f.fn.init.f.fn.ready (social_vendor.js:1)
at new f.fn.init (social_vendor.js:1)
at f (social_vendor.js:1)
at eval (eval at globalEval (social_vendor.js:1), <anonymous>:1:1)
at eval (<anonymous>)

I have tried debugging for the same input.It works fine but at random times it gets empty string and throws undefined.

Upvotes: 0

Views: 291

Answers (0)

Related Questions