Skip to content

Commit

Permalink
fix: tagify onload handler
Browse files Browse the repository at this point in the history
  • Loading branch information
JackScanlon committed Dec 4, 2024
1 parent 7e678b7 commit 085c3ad
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -359,34 +359,38 @@ export default class Tagify {
* @param {dict|*} phenotype optional initialisation template
*/
async #initialise(options, phenotype) {
this.container = createElement('div', {
'className': 'tags-root-container',
});

this.tagbox = createElement('div', {
'className': 'tags-container',
});

this.autocomplete = createElement('div', {
'className': 'tags-autocomplete-container filter-scrollbar',
});

this.field = createElement('input', {
'type': 'text',
'className': 'tags-input-field',
'id': this.uuid,
'placeholder': this.element.placeholder || '',
});

this.tagbox.appendChild(this.field);
this.container.appendChild(this.tagbox);
this.container.appendChild(this.autocomplete);
this.element.type = 'hidden';
this.element.parentNode.insertBefore(this.container, this.element.nextSibling);

this.#buildOptions(options || { }, phenotype)
.catch(e => console.error(e))
.finally(() => {
this.container = createElement('div', {
'className': 'tags-root-container',
});

this.tagbox = createElement('div', {
'className': 'tags-container',
});
if (this.options?.onLoad && this.options.onLoad instanceof Function) {
this.options.onLoad(this);
}

this.autocomplete = createElement('div', {
'className': 'tags-autocomplete-container filter-scrollbar',
});

this.field = createElement('input', {
'type': 'text',
'className': 'tags-input-field',
'id': this.uuid,
'placeholder': this.element.placeholder || '',
});

this.tagbox.appendChild(this.field);
this.container.appendChild(this.tagbox);
this.container.appendChild(this.autocomplete);
this.element.type = 'hidden';
this.element.parentNode.insertBefore(this.container, this.element.nextSibling);

this.#bindEvents();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,17 @@ export const ENTITY_HANDLERS = {
'allowDuplicates': false,
'restricted': true,
'items': options,
}, dataset);
'onLoad': (box) => {
for (let i = 0; i < value.length; ++i) {
const item = value[i];
if (typeof item !== 'object' || !item.hasOwnProperty('name') || !item.hasOwnProperty('value')) {
continue;
}

for (let i = 0; i < value.length; ++i) {
const item = value[i];
if (typeof item !== 'object' || !item.hasOwnProperty('name') || !item.hasOwnProperty('value')) {
continue;
box.addTag(item.name, item.value);
}
}

tagbox.addTag(item.name, item.value);
}
}, dataset);

return tagbox;
},
Expand Down

0 comments on commit 085c3ad

Please sign in to comment.