2024-08-14 16:34:30 +03:00
|
|
|
export default class extends HTMLElement {
|
|
|
|
|
connectedCallback () {
|
2025-09-24 12:07:54 +03:00
|
|
|
this.button.addEventListener('click', (event) => {
|
2025-09-25 09:01:04 +03:00
|
|
|
if (!this.input.value && document.activeElement !== this.input) {
|
|
|
|
|
event.preventDefault()
|
2025-09-24 12:07:54 +03:00
|
|
|
|
2025-09-25 09:01:04 +03:00
|
|
|
this.input.focus()
|
2025-09-24 12:07:54 +03:00
|
|
|
}
|
|
|
|
|
})
|
2026-07-22 20:32:50 +03:00
|
|
|
|
|
|
|
|
document.addEventListener('turbo:before-cache', this.onBeforeCache)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
disconnectedCallback () {
|
|
|
|
|
document.removeEventListener('turbo:before-cache', this.onBeforeCache)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onBeforeCache = () => {
|
|
|
|
|
this.input.value = this.input.getAttribute('value') || ''
|
2024-08-14 16:34:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get input () {
|
|
|
|
|
return this.querySelector('input')
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-24 12:07:54 +03:00
|
|
|
get button () {
|
|
|
|
|
return this.querySelector('button')
|
|
|
|
|
}
|
2024-08-14 16:34:30 +03:00
|
|
|
}
|