Reputation: 139
I have used following jquery for my project.
I want to set initialTags parameter of tagEditor() from attribute of textarea..
For example:
<textarea id="demo3" data-json=""></textarea>
$('#demo3').tagEditor({
initialTags: $(this).attr("data-json"),
placeholder: 'Enter tags ...'
});
But here it doesn't work.. Can anyone help me with this???
Upvotes: 0
Views: 1103
Reputation: 139
https://jsfiddle.net/hasmukhmistry/a0nyw2oy/ - fiddle updated ,
<textarea id="demo3" data-json="some, tags" class="tag-editor-hidden-src" readonly="readonly" style="display: block;"></textarea>
var $demo3 = $('#demo3');
$demo3.tagEditor({
initialTags: $demo3.data("json").split(','),
placeholder: 'Enter tags ...'
});
Thanks @A. Wolff -Profile
Upvotes: 0
Reputation: 9
try this!
$('#demo3').tagEditor({
initialTags: ['tag1', 'tag2', 'tag3']
});
You should take the input data from array. You are taking the data from an attribute of textarea which is empty.
Upvotes: 0
Reputation: 74420
this
in this context isn't the matched element. What you can do is to use a cached variable:
var $demo3 = $('#demo3');
$demo3.tagEditor({
initialTags: $demo3.data("json"),
placeholder: 'Enter tags ...'
});
But don't forget than initialTags
must be an array.
Upvotes: 3