Merge pull request #1333 from basecamp/steps-cant-be-empty
Check for empty values before submitting
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user