forked from fixin.me/fixin.me
Display form errors using custom validity messages
This commit is contained in:
7
app/views/application/errors.turbo_stream.erb
Normal file
7
app/views/application/errors.turbo_stream.erb
Normal 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 %>
|
||||
0
app/views/application/nothing.turbo_stream.erb
Normal file
0
app/views/application/nothing.turbo_stream.erb
Normal file
@@ -44,7 +44,7 @@
|
||||
</header>
|
||||
|
||||
<div id="flashes">
|
||||
<%= render_flash_messages %>
|
||||
<%= render_flash %>
|
||||
</div>
|
||||
|
||||
<%# Allows overwriting/clearing navigation menu for some views %>
|
||||
|
||||
@@ -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 %>
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
<%# For some reason flash messages are duplicated in bot flash and flash.now %>
|
||||
<% flash.discard %>
|
||||
|
||||
Reference in New Issue
Block a user