Files
openfoodnetwork/app/webpacker/controllers/shippingmethod_controller.js
Jean-Baptiste Bellet 1ecfeca88c Populate view with both shipping_method_id & ship_address_same_as_billing
... and then handle correctly the display of the form
2021-08-23 15:23:53 +02:00

45 lines
1.4 KiB
JavaScript

import { Controller } from "stimulus";
export default class extends Controller {
static targets = [
"shippingMethodDescription",
"shippingMethodDescriptionContent",
"shippingMethodAddress",
"shippingAddressCheckbox",
];
connect() {
// Hide shippingMethodDescription by default
}
selectShippingMethod(event) {
const input = event.target;
if (input.tagName === "INPUT") {
// Shipping method description
if (input.dataset.description.length > 0) {
this.shippingMethodDescriptionTarget.style.display = "block";
this.shippingMethodDescriptionContentTarget.innerText =
input.dataset.description;
} else {
this.shippingMethodDescriptionTarget.style.display = "none";
this.shippingMethodDescriptionContentTarget.innerText = null;
}
// Require a ship address
if (
input.dataset.requireaddress === "true" &&
!this.shippingAddressCheckboxTarget.checked
) {
this.shippingMethodAddressTarget.style.display = "block";
} else {
this.shippingMethodAddressTarget.style.display = "none";
}
}
}
showHideShippingAddress() {
if (this.shippingAddressCheckboxTarget.checked) {
this.shippingMethodAddressTarget.style.display = "none";
} else {
this.shippingMethodAddressTarget.style.display = "block";
}
}
}