From c1643030a27ac1fce7f7e457ab9ea56b30ca7ad1 Mon Sep 17 00:00:00 2001 From: cryptogopher Date: Mon, 22 Jan 2024 02:34:13 +0100 Subject: [PATCH] Avoid re-rendering form on errors --- app/views/units/new.turbo_stream.erb | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/app/views/units/new.turbo_stream.erb b/app/views/units/new.turbo_stream.erb index 6f347f4..dd4d73f 100644 --- a/app/views/units/new.turbo_stream.erb +++ b/app/views/units/new.turbo_stream.erb @@ -1,16 +1,18 @@ <%= turbo_stream.disable :add_unit %> +<%# TODO: disable only form-opening actions %> <%= turbo_stream.disable_all 'td.actions .button' %> -<% case %> -<% when @unit.errors.present? %> +<% if @unit.errors.present? %> <%= turbo_stream.replace @unit, partial: 'form' %> -<% when @unit.base.nil? %> - <%= turbo_stream.prepend :units, partial: 'form' %> <% else %> - <%= turbo_stream.after @unit.base, partial: 'form' %> -<% end %> + <% if @unit.base.nil? %> + <%= turbo_stream.prepend :units, partial: 'form' %> + <% else %> + <%= turbo_stream.after @unit.base, partial: 'form' %> + <% end %> -<%= turbo_stream.update :unit_form_frame do %> - <%= form_with model: @unit, html: {id: :unit_form} do %> + <%= turbo_stream.update :unit_form_frame do %> + <%= form_with model: @unit, html: {id: :unit_form} do %> + <% end %> <% end %> <% end %>