Support custom validation messages
This commit is contained in:
@@ -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 })
|
||||
}
|
||||
|
||||
@@ -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 can‘t be blank" } %>
|
||||
|
||||
<button type="submit" class="btn btn--link center">
|
||||
<span>Create board</span>
|
||||
|
||||
Reference in New Issue
Block a user