Merge pull request #1333 from basecamp/steps-cant-be-empty

Check for empty values before submitting
This commit is contained in:
Andy Smith
2025-10-16 11:24:03 -05:00
committed by GitHub
2 changed files with 14 additions and 3 deletions
+12 -1
View File
@@ -2,7 +2,7 @@ import { Controller } from "@hotwired/stimulus"
import { debounce, nextFrame } from "helpers/timing_helpers";
export default class extends Controller {
static targets = [ "cancel", "submit" ]
static targets = [ "cancel", "submit", "input" ]
static values = {
debounceTimeout: { type: Number, default: 300 }
@@ -16,6 +16,17 @@ export default class extends Controller {
this.element.requestSubmit()
}
preventEmptySubmit(event) {
const input = this.hasInputTarget ? this.inputTarget : null
if (input) {
const value = (input.value || "").trim()
if (value.length === 0) {
event.preventDefault()
}
}
}
debouncedSubmit(event) {
this.submit(event)
}