Prevent board names with only spaces and show validation message

This commit is contained in:
Andy Smith
2025-12-04 11:37:27 -06:00
parent 78ea18b5da
commit 5c4fe9fe8b
2 changed files with 8 additions and 3 deletions
@@ -21,8 +21,13 @@ export default class extends Controller {
if (input) {
const value = (input.value || "").trim()
if (value.length === 0) {
const isEmpty = value.length === 0
if (isEmpty) {
event.preventDefault()
input.setCustomValidity(input.validationMessage || "Please fill out this field")
input.reportValidity()
input.addEventListener("input", () => input.setCustomValidity(""), { once: true })
}
}
}
+2 -2
View File
@@ -1,9 +1,9 @@
<% @page_title = "Create a new board" %>
<div class="panel panel--centered">
<%= form_with model: @board, class: "flex flex-column gap", data: { controller: "form" } do |form| %>
<%= form_with model: @board, class: "flex flex-column gap", data: { controller: "form", action: "submit->form#preventEmptySubmit" } do |form| %>
<h1 class="txt-x-large margin-none font-weight-black"><%= @page_title %></h1>
<%= form.text_field :name, required: true, class: "input full-width", autofocus: true, autocomplete: "off",placeholder: "Name it…", data: { action: "keydown.esc@document->form#cancel" } %>
<%= form.text_field :name, required: true, class: "input full-width", autofocus: true, autocomplete: "off", placeholder: "Name it…", data: { form_target: "input", action: "keydown.esc@document->form#cancel" } %>
<button type="submit" class="btn btn--link center">
<span>Create board</span>