Prevent table columns' width change on form toggle

This commit is contained in:
2026-11-05 18:00:34 +01:00
parent 4940e6de86
commit 3655a74b94
23 changed files with 150 additions and 90 deletions
+9 -9
View File
@@ -1,16 +1,16 @@
<%= tabular_fields_for @quantity, form: form_tag do |form| %>
<%- tag.tr id: row, class: "form", onkeydown: "formProcessKey(event)",
data: {link: link, form: form_tag, hidden_row: hidden_row} do %>
<%# locals: (record: Quantity.new, **attrs) %>
<%= tabular_fields_for record, form: attrs.dig(:data, :form) do |form| %>
<%- tag.tr class: "form", onkeydown: "formProcessKey(event)", **attrs do %>
<td style="--depth:<%= @quantity.depth %>">
<td style="--depth:<%= form.object.depth %>">
<%= form.text_field :name, autofocus: true, class: 'hstretch', required: true %>
<td><%= form.text_area :description, class: 'hstretch', escape: false, rows: 1 %>
<td class="flex">
<%= form.button %>
<%= image_link_to t(:cancel), "close-outline", quantities_path,
class: 'dangerous', name: :cancel,
onclick: render_turbo_stream('form_close', {row: row}) %>
<td><%= form.button %>
<td>
<%= image_link_to t(:discard), "close-outline", quantities_path,
class: 'dangerous', name: :discard,
onclick: render_turbo_stream('form_close', {id: attrs[:id]}) %>
<td><!-- TODO: add aria-disabled drag handle with proper vertical alignment? -->
<% end %>
<% end %>
+1 -1
View File
@@ -1,2 +1,2 @@
<%= turbo_stream.close_form row %>
<%= turbo_stream.close_form id %>
<%= turbo_stream.update :flashes %>
+2 -2
View File
@@ -12,11 +12,11 @@
<td><%= quantity.description %>
<% if current_user.at_least(:active) %>
<td class="flex">
<td>
<%= image_link_to t('.new_subquantity'), 'plus-outline',
new_quantity_path(quantity), id: dom_target(:new, quantity, :link),
onclick: 'this.blur();', data: {turbo_stream: true} %>
<td>
<%= image_button_to_if quantity.destroyable?, t('.destroy'), 'delete-outline',
quantity_path(quantity), method: :delete %>
+8 -7
View File
@@ -1,12 +1,13 @@
<% ids = {row: dom_target(:edit, @quantity),
hidden_row: dom_target(@quantity),
link: nil,
form_tag: dom_target(:edit, @quantity, :form)} %>
<% attrs = {record: @quantity,
id: dom_target(:edit, @quantity),
data: {form: dom_target(:edit, @quantity, :form),
hidden_row: dom_target(@quantity),
link: nil}} %>
<%= turbo_stream.append_all 'body' do %>
<%- tabular_form_with model: @quantity, html: {id: ids[:form_tag]} do %>
<%- tabular_form_with model: @quantity, html: {id: attrs[:data][:form]} do %>
<% end %>
<% end %>
<%= turbo_stream.hide ids[:hidden_row] %>
<%= turbo_stream.after @quantity, partial: 'form', locals: ids -%>
<%= turbo_stream.hide attrs[:data][:hidden_row] %>
<%= turbo_stream.after @quantity, partial: 'form', locals: attrs -%>
+8 -3
View File
@@ -15,17 +15,22 @@
<th class="hmintext"><%= Quantity.human_attribute_name(:name) %>
<th class="hexpand"><%= Quantity.human_attribute_name(:description) %>
<% if current_user.at_least(:active) %>
<th><%= t :actions %>
<th>
<th colspan="3"><%= t :actions %>
<tr id="quantity_" hidden
ondragover="dragOver(event)" ondrop="drop(event)"
ondragenter="dragEnter(event)" ondragleave="dragLeave(event)"
data-drop-id="quantity_"
data-drop-id-param="<%= field_name(:quantity, :parent_id) %>">
<th colspan="4"><%= t '.top_level_drop' %>
<th colspan="5"><%= t '.top_level_drop' %>
<% end %>
<%= render @quantities %>
<% if current_user.at_least(:active) %>
<tr id="endmark" hidden>
<tfoot>
<%= render partial: 'form', locals: {hidden: true} %>
<% end %>
</table>
+8 -7
View File
@@ -1,15 +1,16 @@
<% target_id = dom_target(:new, @quantity.parent || :quantity) %>
<% ids = {row: target_id,
hidden_row: nil,
link: dom_target(target_id, :link),
form_tag: dom_target(target_id, :form)} %>
<% attrs = {record: @quantity,
id: target_id,
data: {form: dom_target(target_id, :form),
hidden_row: nil,
link: dom_target(target_id, :link)}} %>
<%= turbo_stream.disable ids[:link] -%>
<%= turbo_stream.disable attrs[:data][:link] -%>
<%= turbo_stream.append_all 'body' do %>
<%- tabular_form_with model: @quantity, html: {id: ids[:form_tag]} do |form| %>
<%- tabular_form_with model: @quantity, html: {id: attrs[:data][:form]} do |form| %>
<%= form.hidden_field :parent_id if @quantity.parent_id? %>
<% end %>
<% end %>
<%= turbo_stream.after @quantity.parent || :quantity_, partial: 'form', locals: ids %>
<%= turbo_stream.after @quantity.parent || :quantity_, partial: 'form', locals: attrs %>