fix: only use destination's pickup values

This commit is contained in:
Björn Fromme
2024-01-28 17:49:46 +01:00
parent 85200e2960
commit 75bd055474
18 changed files with 286 additions and 106 deletions
@@ -0,0 +1,35 @@
import { Controller } from '@hotwired/stimulus'
import { useFetch } from '../mixins/use_fetch'
export default class extends Controller {
static targets = [ 'form', 'container', 'spinner' ]
static values = { url: String, loading: Boolean }
connect() {
useFetch(this)
}
update() {
this.loadingValue = true
const formData = new FormData(this.formTarget)
fetch(this.urlValue, { method: 'POST', body: formData })
.then(this.checkStatus)
.then(this.parseHTML)
.then(response => {
this.containerTarget.innerHTML = response
})
.catch(error => {
})
.finally(() => {
this.loadingValue = false
})
}
loadingValueChanged(loading) {
if (this.hasSpinnerTarget) {
this.spinnerTarget.classList.toggle('hidden', false === loading)
}
}
}