|
|
|
|
@ -19,21 +19,32 @@ export default class extends HTMLElement {
|
|
|
|
|
|
|
|
|
|
fields.forEach((field) => {
|
|
|
|
|
const input = submitterItemEl.querySelector(`submitters-autocomplete[data-field="${field}"] input`)
|
|
|
|
|
const textarea = submitterItemEl.querySelector(`submitters-autocomplete[data-field="${field}"] textarea`)
|
|
|
|
|
|
|
|
|
|
if (input && item[field]) {
|
|
|
|
|
input.value = item[field]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (textarea && item[field]) {
|
|
|
|
|
textarea.value = textarea.value.replace(/[^;,\s]+$/, item[field] + ' ')
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fetch = (text, resolve) => {
|
|
|
|
|
if (text) {
|
|
|
|
|
const queryParams = new URLSearchParams({ q: text, field: this.dataset.field })
|
|
|
|
|
const q = text.split(/[;,\s]+/).pop().trim()
|
|
|
|
|
|
|
|
|
|
if (q) {
|
|
|
|
|
const queryParams = new URLSearchParams({ q, field: this.dataset.field })
|
|
|
|
|
|
|
|
|
|
fetch('/api/submitters_autocomplete?' + queryParams).then(async (resp) => {
|
|
|
|
|
const items = await resp.json()
|
|
|
|
|
|
|
|
|
|
resolve(items)
|
|
|
|
|
if (q.length < 3) {
|
|
|
|
|
resolve(items.filter((e) => e[this.dataset.field].startsWith(q)))
|
|
|
|
|
} else {
|
|
|
|
|
resolve(items)
|
|
|
|
|
}
|
|
|
|
|
}).catch(() => {
|
|
|
|
|
resolve([])
|
|
|
|
|
})
|
|
|
|
|
@ -51,6 +62,6 @@ export default class extends HTMLElement {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get input () {
|
|
|
|
|
return this.querySelector('input')
|
|
|
|
|
return this.querySelector('input') || this.querySelector('textarea')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|