forked from fixin.me/fixin.me
Add cancel() method to form_controller that handles all close cases: - tabular forms (<tr>): removes inner form, re-enables link, shows hidden row - measurements create form: removes self, enables trigger link, shows no-items Data attributes already present on controller elements (data-form, data-link, data-hidden-row) drive the behaviour. Two extra attributes on the create form (data-cancel-enable, data-cancel-show) cover the non-tabular case. Delete now-unused _form_close and _edit_form_close partial templates. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
42 lines
1.8 KiB
Plaintext
42 lines
1.8 KiB
Plaintext
<%= tabular_form_with model: Measurement.new, id: :measurement_form,
|
|
class: 'topside-area flex vertical center',
|
|
html: {data: {controller: 'form', action: 'keydown->form#processKey',
|
|
cancel_enable: 'new_measurement_link',
|
|
cancel_show: 'no_items'}} do |form| %>
|
|
|
|
<table class="items-table center">
|
|
<tbody id="readouts">
|
|
<%= tabular_fields_for @measurement do |form| %>
|
|
<tr class="italic">
|
|
<td class="hexpand hmin50"><%= t '.taken_at_html' %></td>
|
|
<td colspan="3" class="ralign">
|
|
<%= form.datetime_field :taken_at, required: true, value: Time.current.strftime('%Y-%m-%dT%H:%M') %>
|
|
</td>
|
|
</tr>
|
|
<% end %>
|
|
</tbody>
|
|
</table>
|
|
|
|
<%# TODO: right-click selection; unnecessary with hierarchical tags? %>
|
|
<details id="quantity_select" class="center hexpand" open
|
|
data-controller="details"
|
|
data-action="focusout->details#close change->details#change keydown->details#processKey">
|
|
<summary autofocus>
|
|
<!-- TODO: Set content with CSS when span empty to avoid duplication -->
|
|
<span data-prompt="<%= t('.select_quantity') %>" data-details-target="countLabel">
|
|
<%= t('.select_quantity') %>
|
|
</span>
|
|
<%= image_button_tag t(:apply), "update", name: nil, disabled: true,
|
|
formaction: new_readout_path, formmethod: :get, formnovalidate: true,
|
|
data: {turbo_stream: true, details_target: 'submitButton'} %>
|
|
</summary>
|
|
<ul data-details-target="list"><%= quantities_check_boxes(@quantities) %></ul>
|
|
</details>
|
|
|
|
<div class="flex reverse">
|
|
<%= form.button id: :create_measurement_button, disabled: true -%>
|
|
<%= image_link_to t(:cancel), "close-outline", measurements_path, name: :cancel,
|
|
class: 'dangerous', data: {action: 'click->form#cancel'} %>
|
|
</div>
|
|
<% end %>
|