Change the paymentmethod controller to handle both desc and form

Add tests as well

Update _payment.html.haml

Update _payment.html.haml
This commit is contained in:
Jean-Baptiste Bellet
2021-11-16 15:24:25 +01:00
committed by Matt-Yorkley
parent 53d01b1275
commit 3063b041d1
3 changed files with 76 additions and 6 deletions

View File

@@ -1,9 +1,25 @@
import { Controller } from "stimulus";
export default class extends Controller {
static targets = ["panel"];
static targets = ["paymentMethod"];
connect() {
this.hideAll();
}
selectPaymentMethod(event) {
this.panelTarget.innerHTML = `<span>${event.target.dataset.paymentmethodDescription}</span>`;
this.panelTarget.style.display = "block";
this.hideAll();
const paymentMethodContainerId = event.target.dataset.paymentmethodId;
const paymentMethodContainer = document.getElementById(
paymentMethodContainerId
);
paymentMethodContainer.style.display = "block";
}
hideAll() {
Array.from(
document.getElementsByClassName("paymentmethod-container")
).forEach((e) => {
e.style.display = "none";
});
}
}