Handle when input is already checked

ie. user hasn't click on anything
This commit is contained in:
Jean-Baptiste Bellet
2021-12-16 12:25:28 +01:00
parent 6ef7256295
commit 7b6aa99de2
3 changed files with 21 additions and 9 deletions

View File

@@ -1,9 +1,20 @@
import { Controller } from "stimulus";
export default class extends Controller {
static targets = ["paymentMethod"];
static targets = ["input"];
connect() {
this.inputTargets.forEach((i) => {
if (i.checked) {
this.doSelectPaymentMethod(i.dataset.paymentmethodId);
}
});
}
selectPaymentMethod(event) {
const paymentMethodContainerId = event.target.dataset.paymentmethodId;
this.doSelectPaymentMethod(event.target.dataset.paymentmethodId);
}
doSelectPaymentMethod(paymentMethodContainerId) {
Array.from(
document.getElementsByClassName("paymentmethod-container")
).forEach((e) => {