mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-25 20:46:48 +00:00
42 lines
1.3 KiB
JavaScript
42 lines
1.3 KiB
JavaScript
import { Controller } from "stimulus";
|
|
export default class extends Controller {
|
|
static targets = [
|
|
"shippingMethodDescription",
|
|
"shippingMethodAddress",
|
|
"shippingAddressCheckbox",
|
|
];
|
|
connect() {}
|
|
|
|
selectShippingMethod(event) {
|
|
const input = event.target;
|
|
if (input.tagName === "INPUT") {
|
|
// -- Shipping method description
|
|
// Hide all shipping method descriptions
|
|
this.shippingMethodDescriptionTargets.forEach((t) => {
|
|
t.style.display = "none";
|
|
});
|
|
// but not the one we want ie. the one that matches the shipping method id
|
|
this.shippingMethodDescriptionTargets.find(
|
|
(e) => e.dataset["shippingmethodid"] == input.value
|
|
).style.display = "block";
|
|
// -- 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";
|
|
}
|
|
}
|
|
}
|