Display form errors using custom validity messages

This commit is contained in:
2026-07-28 00:45:08 +02:00
parent 5d051de666
commit eb2797bd90
13 changed files with 81 additions and 51 deletions

View File

@@ -0,0 +1,7 @@
<%= turbo_stream.validate dom_target(*@target, :form) do %>
<% @record.errors.attribute_names.map do |attr| %>
<%= tag.span data: {name: field_name(dom_class(@record), attr)} do %>
<%- @record.errors.full_messages_for(attr).map { |m| m + '.' }.join(' ') %>
<% end %>
<% end %>
<% end %>

View File

@@ -44,7 +44,7 @@
</header>
<div id="flashes">
<%= render_flash_messages %>
<%= render_flash %>
</div>
<%# Allows overwriting/clearing navigation menu for some views %>

View File

@@ -1,6 +1,6 @@
<%= yield %>
<%# Some views may convert ActiveRecord errors to flashes, render at the end. %>
<%# Render unconditionally, to clear previous flash messages. %>
<%= turbo_stream.update :flashes do %>
<%= render_flash_messages %>
<%= render_flash %>
<% end %>
<%= yield %>

View File

@@ -1,2 +1 @@
<%# For some reason flash messages are duplicated in bot flash and flash.now %>
<% flash.discard %>