Files
openfoodnetwork/app/webpacker/controllers/toggle_button_disabled_controller.js
Gaetan Craig-Riou 0a249d7722 Fix ButtonEnableToggleController to remove hacky button disable
As per review comment, use data-disable-with="false" do prevent Rails
from automatically enabling the "Apply" button. We can then remove
the timeout hack.
2023-05-15 13:42:39 +10:00

25 lines
650 B
JavaScript

import { Controller } from "stimulus";
// Since Rails 7 it adds "data-disabled-with" property to submit, you'll need to add
// 'data-disable-with="false' for this to function as expected, ie:
//
// <input id="test-submit" type="submit" data-disable-with="false" data-toggle-button-disabled-target="button"/>
//
export default class extends Controller {
static targets = ["button"];
connect() {
if (this.hasButtonTarget) {
this.buttonTarget.disabled = true;
}
}
inputIsChanged(e) {
if (e.target.value !== "") {
this.buttonTarget.disabled = false;
} else {
this.buttonTarget.disabled = true;
}
}
}