How do I remove the defaultText attribute after at least one tag is added for the tagsInput JQuery library?

Viewed 64

Problem

I have a textarea with inputTag JS: (my js is different than the fiddle, but the fiddle will provide a MWE to display the feature in)

$('#box').tagsInput({
    'width': 'auto',
    'delimiter': ',',
    'defaultText': 'Enter email',
    allowDuplicates: true
});

I want to delete the defaultText after at least one tag is added to the box. I really just want the html placeholder attribute functionality. The issue with using that is that the JS and CSS replace the original text box, also replacing the placeholder.

tag library at:

https://github.com/xoxco/jQuery-Tags-Input/tree/master/src

js fiddle at:

https://jsfiddle.net/6aa2adba/

Example of issue:

enter image description here

1 Answers

You can change the underlying data-default that is your defaultText. You place this snippet when you want to remove the defaultText. Check the size of your array and if all values are removed you can call this but with the correct text

jsfiddle for inputTags

$('#invite-emails_tag').attr('data-default','');
Related