Use controller to disable empty comment submit

This commit is contained in:
Andy Smith
2025-10-01 16:56:55 -05:00
parent 4243db372b
commit 80e072f845
3 changed files with 13 additions and 9 deletions
+11 -1
View File
@@ -2,7 +2,7 @@ import { Controller } from "@hotwired/stimulus"
import { debounce } from "helpers/timing_helpers";
export default class extends Controller {
static targets = [ "cancel" ]
static targets = [ "cancel", "submit" ]
static values = {
debounceTimeout: { type: Number, default: 300 }
@@ -37,6 +37,16 @@ export default class extends Controller {
event.preventDefault()
}
disableEmptySubmit(event) {
var value = event.target.value.replace(/<\/?[^>]+(>|$)/g, "")
if (value) {
this.submitTarget.removeAttribute("disabled")
} else {
this.submitTarget.setAttribute("disabled", true)
}
}
select(event) {
event.target.select()
}