2024-05-02 07:24:31 -06:00
|
|
|
import { Controller } from "@hotwired/stimulus";
|
|
|
|
|
|
|
|
export default class extends Controller {
|
2024-10-14 23:09:27 +02:00
|
|
|
static targets = ["replacementField", "submitButton"];
|
|
|
|
static classes = ["dangerousAction", "safeAction"];
|
2024-05-02 07:24:31 -06:00
|
|
|
static values = {
|
|
|
|
submitTextWhenReplacing: String,
|
2024-10-14 23:09:27 +02:00
|
|
|
submitTextWhenNotReplacing: String,
|
|
|
|
};
|
2024-05-02 07:24:31 -06:00
|
|
|
|
|
|
|
updateSubmitButton() {
|
2024-05-23 08:09:33 -04:00
|
|
|
if (this.replacementFieldTarget.value) {
|
2024-10-14 23:09:27 +02:00
|
|
|
this.submitButtonTarget.value = this.submitTextWhenReplacingValue;
|
|
|
|
this.#markSafe();
|
2024-05-02 07:24:31 -06:00
|
|
|
} else {
|
2024-10-14 23:09:27 +02:00
|
|
|
this.submitButtonTarget.value = this.submitTextWhenNotReplacingValue;
|
|
|
|
this.#markDangerous();
|
2024-05-02 07:24:31 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#markSafe() {
|
2024-10-14 23:09:27 +02:00
|
|
|
this.submitButtonTarget.classList.remove(...this.dangerousActionClasses);
|
|
|
|
this.submitButtonTarget.classList.add(...this.safeActionClasses);
|
2024-05-02 07:24:31 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#markDangerous() {
|
2024-10-14 23:09:27 +02:00
|
|
|
this.submitButtonTarget.classList.remove(...this.safeActionClasses);
|
|
|
|
this.submitButtonTarget.classList.add(...this.dangerousActionClasses);
|
2024-05-02 07:24:31 -06:00
|
|
|
}
|
|
|
|
}
|