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.
This commit is contained in:
Gaetan Craig-Riou
2023-05-01 16:28:07 +10:00
committed by Maikel Linke
parent e5f14177d3
commit aa526a639c
4 changed files with 109 additions and 6 deletions

View File

@@ -0,0 +1,22 @@
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;
}
}
}