34 lines
939 B
JavaScript
34 lines
939 B
JavaScript
import { Controller } from '@hotwired/stimulus'
|
|
|
|
/**
|
|
* Unchecks conflicting additional services as soon as one is selected, so the user sees the
|
|
* result immediately instead of waiting for the debounced htmx refresh. The server resolves
|
|
* the same conflicts again and stays the source of truth.
|
|
*/
|
|
export default class extends Controller {
|
|
|
|
static targets = [ 'input' ]
|
|
|
|
select(event) {
|
|
const input = event.target
|
|
|
|
if (!input.checked) {
|
|
return
|
|
}
|
|
|
|
const group = input.dataset.exclusionGroup
|
|
|
|
if (!group) {
|
|
return
|
|
}
|
|
|
|
const exclusive = '1' === input.dataset.exclusive
|
|
|
|
this.inputTargets
|
|
.filter(other => other !== input)
|
|
.filter(other => other.dataset.exclusionGroup === group)
|
|
.filter(other => exclusive || '1' === other.dataset.exclusive)
|
|
.forEach(other => { other.checked = false })
|
|
}
|
|
}
|