2023-04-27 10:10:57 +02:00
|
|
|
import { Controller } from '@hotwired/stimulus';
|
|
|
|
|
2023-12-19 15:30:12 +01:00
|
|
|
export class EnableSubmitIfCheckedController extends Controller {
|
2023-04-27 10:10:57 +02:00
|
|
|
static targets = ['submit'];
|
|
|
|
declare readonly submitTarget: HTMLButtonElement;
|
|
|
|
|
|
|
|
click() {
|
|
|
|
if (
|
2023-12-19 15:30:12 +01:00
|
|
|
this.element.querySelectorAll('input[type="radio"]:checked').length > 0 ||
|
|
|
|
this.element.querySelectorAll('input[type="checkbox"]:checked').length > 0
|
2023-04-27 10:10:57 +02:00
|
|
|
) {
|
|
|
|
this.submitTarget.disabled = false;
|
2023-12-19 15:30:12 +01:00
|
|
|
} else {
|
|
|
|
this.submitTarget.disabled = true;
|
2023-04-27 10:10:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|