Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/tags-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ const SEPERATOR = ',';
const COPY_PROPS = 'placeholder pattern spellcheck autocomplete autocapitalize autofocus accessKey accept lang minLength maxLength required'.split(' ');

export default function tagsInput(input) {
var public_api = {
"tags" : getTags
};

function createElement(type, name, text, attributes) {
let el = document.createElement(type);
if (name) el.className = name;
Expand All @@ -25,9 +29,13 @@ export default function tagsInput(input) {
return all===true ? Array.prototype.slice.call(base.querySelectorAll(selector)) : base.querySelector(selector);
}

function getValue() {
function getTags() {
return $('.tag', true)
.map( tag => tag.textContent )
}

function getValue() {
getTags()
.concat(base.input.value || [])
.join(SEPERATOR);
}
Expand All @@ -39,7 +47,7 @@ export default function tagsInput(input) {

function save() {
input.value = getValue();
input.dispatchEvent(new Event('change'));
input.dispatchEvent(new CustomEvent('change', {detail: callbacks}));
}

// Return false if no need to add a tag
Expand Down Expand Up @@ -213,7 +221,7 @@ export default function tagsInput(input) {
// This means that users who only want one thing don't have to enter commas
base.input.addEventListener('input', () => {
input.value = getValue();
input.dispatchEvent(new Event('input'));
input.dispatchEvent(new CustomEvent('input', {detail: callbacks}));
});

// One tick after pasting, parse pasted text as CSV:
Expand All @@ -227,6 +235,7 @@ export default function tagsInput(input) {

// Add tags for existing values
savePartialInput(input.value);
return public_api;
}

// make life easier:
Expand Down