2024-05-02 07:24:31 -06:00
|
|
|
import { Controller } from "@hotwired/stimulus";
|
|
|
|
|
|
|
|
export default class extends Controller {
|
2025-04-30 18:14:22 -04:00
|
|
|
static targets = [
|
|
|
|
"replacementField",
|
|
|
|
"destructiveSubmitButton",
|
|
|
|
"safeSubmitButton",
|
|
|
|
];
|
|
|
|
|
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
|
|
|
|
2025-04-30 18:14:22 -04:00
|
|
|
chooseSubmitButton() {
|
2024-05-23 08:09:33 -04:00
|
|
|
if (this.replacementFieldTarget.value) {
|
2025-04-30 18:14:22 -04:00
|
|
|
this.destructiveSubmitButtonTarget.hidden = true;
|
|
|
|
this.safeSubmitButtonTarget.textContent =
|
|
|
|
this.submitTextWhenReplacingValue;
|
|
|
|
this.safeSubmitButtonTarget.hidden = false;
|
2024-05-02 07:24:31 -06:00
|
|
|
} else {
|
2025-04-30 18:14:22 -04:00
|
|
|
this.destructiveSubmitButtonTarget.textContent =
|
|
|
|
this.submitTextWhenNotReplacingValue;
|
|
|
|
this.destructiveSubmitButtonTarget.hidden = false;
|
|
|
|
this.safeSubmitButtonTarget.hidden = true;
|
2024-05-02 07:24:31 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|