Single select form without action buttons

This commit is contained in:
2026-01-15 19:00:25 +01:00
parent 207699584b
commit 1acb179851
7 changed files with 22 additions and 52 deletions

View File

@@ -1,32 +1,16 @@
<%= tabular_form_with model: Measurement.new do |form| %>
<fieldset>
<legend>
<%= tag.span t('.no_items'), id: :measurement_form_legend %>
<%= image_link_to '', "pencil-outline", measurements_path,
data: {turbo_stream: true} %>
</legend>
<table class="items">
<table class="items centered">
<tbody id="readouts">
<tr id="readouts_form">
<td>
<%= select_tag :id,
options_from_collection_for_select(
@quantities, :id, ->(q){ quantity_option_text(q, false) }
), class: 'quantity' %>
</td>
<td colspan="3">
<div class="actions">
<% opts = {formaction: new_readout_path, formmethod: :get,
formnovalidate: true, data: {turbo_stream: true}} %>
<%= image_button_tag t('.new_readout'), 'plus-outline', id: :new_readout,
value: nil, **opts -%>
<%= image_button_tag t('.new_children'), 'plus-multiple-outline',
value: :children, **opts -%>
<%#= image_button_tag t('.new_subtree'), 'plus-multiple-outline',
value: :subtree, **opts -%>
<%= image_button_tag t('.new_leaves'), 'plus-multiple-outline',
value: :leaves, **opts -%>
</div>
<td colspan="4">
<%= collection_select :quantity, :id, @quantities, :id, :to_s_with_depth,
{prompt: t('.select_quantity'), disabled: '', selected: ''},
{name: :id, class: 'quantity vexpand',
onchange: "this.form.requestSubmit(new_readout_submit);"} %>
<%= form.submit id: :new_readout_submit, name: nil, value: nil,
formaction: new_readout_path, formmethod: :get, formnovalidate: true,
hidden: true, data: {turbo_stream: true} %>
</td>
</tr>
</tbody>

View File

@@ -1,5 +1,4 @@
<%= turbo_stream.remove dom_id(@quantity, :new, :readout) %>
<%= turbo_stream.disable_all 'button[name="discard"]' if @prev_quantities.one? %>
<%= turbo_stream.update_all "#id option[value=\"#{@quantity.id}\"]",
quantity_option_text(@quantity, false) %>
<%= turbo_stream.enable_all "select.quantity option[value='#{@quantity.id}']" %>
<%= render partial: 'form_repath' %>

View File

@@ -1,10 +1,8 @@
<%= render partial: 'form_repath' %>
<%# is .one? proper condition? can @readouts be empty? %>
<%= turbo_stream.enable_all 'button[name="discard"]' if @prev_quantities.one? %>
<%# TODO: disable Add actions accordingly (e.g. disable Children if childless or all
children already added), then disable option once all actions unavailable %>
<% @readouts.each do |r| %>
<%= turbo_stream.update_all "#id option[value=\"#{r.quantity_id}\"]",
quantity_option_text(r.quantity, true) %>
<%= turbo_stream.disable_all "select.quantity option[value='#{r.quantity_id}']" %>
<% end %>
<%= turbo_stream.before :readouts_form do %>
<%= render partial: 'form', collection: @readouts, as: :readout %>