Files
openfoodnetwork/app/webpacker/controllers/toggle_button_disabled_controller.js
Gaetan Craig-Riou aa526a639c Checkout payment page, enable voucher "apply" button when code entered
The "apply" button is disabled by default. If left enabled, a customer
could try to apply an empty voucher, which results in system trying
to move to the order summary step, an unexpected behaviour!
We only enable the button when something is entered in the input.
2023-05-15 13:42:39 +10:00

23 lines
499 B
JavaScript

import { Controller } from "stimulus";
export default class extends Controller {
static targets = ["button"];
connect() {
// Hacky way to go arount mrjus automatically enabling/disabling form element
setTimeout(() => {
if (this.hasButtonTarget) {
this.buttonTarget.disabled = true;
}
}, 100);
}
inputIsChanged(e) {
if (e.target.value !== "") {
this.buttonTarget.disabled = false;
} else {
this.buttonTarget.disabled = true;
}
}
}