Support custom validation messages

This commit is contained in:
Andy Smith
2025-12-04 11:43:55 -06:00
parent 5c4fe9fe8b
commit 23ec3f129a
2 changed files with 2 additions and 2 deletions
@@ -25,7 +25,7 @@ export default class extends Controller {
if (isEmpty) {
event.preventDefault()
input.setCustomValidity(input.validationMessage || "Please fill out this field")
input.setCustomValidity(input.dataset.validationMessage || "Please fill out this field")
input.reportValidity()
input.addEventListener("input", () => input.setCustomValidity(""), { once: true })
}
+1 -1
View File
@@ -3,7 +3,7 @@
<div class="panel panel--centered">
<%= 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: { form_target: "input", 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", validation_message: "Board names cant be blank" } %>
<button type="submit" class="btn btn--link center">
<span>Create board</span>