|
1 | 1 | <%# app/views/better_together/checklist_items/_form.html.erb %> |
2 | 2 | <%# Safely resolve optional locals to avoid NameError when partial is rendered without all locals %> |
3 | 3 | <% current = (local_assigns[:form_object] || local_assigns[:checklist_item] || local_assigns[:new_checklist_item]) %> |
4 | | -<% form_base_id = current ? dom_id(current) : 'new_checklist_item' %> |
5 | | -<%= turbo_frame_tag (current ? "#{dom_id(current)}_frame" : 'new_checklist_item') do %> |
6 | | - <%= form_with(model: current || local_assigns[:new_checklist_item], url: form_url || request.path, local: false) do |f| %> |
| 4 | +<%# Use stable DOM ids for new records so Turbo replacements target the same element. |
| 5 | + Only use the record dom_id when the record is persisted. %> |
| 6 | +<% form_base_id = (current && current.persisted?) ? dom_id(current) : 'new_checklist_item' %> |
| 7 | +<%= turbo_frame_tag ((current && current.persisted?) ? "#{dom_id(current)}_frame" : 'new_checklist_item') do %> |
| 8 | + <%= form_with(model: current || local_assigns[:new_checklist_item], url: form_url || request.path, local: false, data: { controller: 'better_together--form-validation' }) do |f| %> |
7 | 9 | <%# Title and short instructions for the form %> |
8 | 10 | <div class="mb-3"> |
9 | 11 | <h5 class="mb-1"><%= current && current.persisted? ? t('better_together.checklist_items.edit_title', default: 'Edit checklist item') : t('better_together.checklist_items.new_title', default: 'New checklist item') %></h5> |
10 | 12 | <p class="text-muted small mb-0"><%= t('better_together.checklist_items.form_hint', default: 'Provide a short label and optional details. Use privacy to control who sees this item.') %></p> |
11 | 13 | </div> |
12 | 14 | <div class="mb-2"> |
13 | 15 | <%= required_label(f, :label, class: 'form-label') %> |
14 | | - <%= f.text_field :label, class: 'form-control', aria: { describedby: "#{form_base_id}_label_help" } %> |
| 16 | + <%= f.text_field :label, class: 'form-control', required: true, aria: { describedby: "#{form_base_id}_label_help", 'required' => 'true' } %> |
15 | 17 | <div id="<%= "#{form_base_id}_label_help" %>" class="form-text text-muted"><%= t('better_together.checklist_items.hint_label', default: 'Short title for the checklist item (required).') %></div> |
16 | 18 | </div> |
17 | 19 |
|
|
50 | 52 | <div class="d-flex justify-content-end"> |
51 | 53 | <% submit_label = current && current.persisted? ? t('globals.update', default: 'Update') : t('globals.create', default: 'Create') %> |
52 | 54 | <%= f.submit submit_label, class: 'btn btn-primary btn-sm' %> |
53 | | - <%= button_tag t('globals.cancel', default: 'Cancel'), type: 'submit', name: 'cancel', value: 'true', class: 'btn btn-secondary btn-sm ms-2' %> |
| 55 | + <%# Only show a Cancel button when editing an existing record (not when creating a new one) %> |
| 56 | + <% if current && current.persisted? %> |
| 57 | + <%= button_tag t('globals.cancel', default: 'Cancel'), type: 'submit', name: 'cancel', value: 'true', class: 'btn btn-secondary btn-sm ms-2' %> |
| 58 | + <% end %> |
54 | 59 | </div> |
55 | 60 | <% end %> |
56 | 61 | <% end %> |
0 commit comments