feat: exclusion groups for additional services
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
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 })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user