Skip to content

Commit ecd1d7b

Browse files
committed
Fix button_to for forms
Forms shouldn't be nested, particularly their submit buttons shouldn't. With this commit, we fix this issue. For some forms, we had to provide an ID and assign a separate submit button outside the form to keep the current appearance and make the least changes. A more proper solution should be found in the future.
1 parent 05828e2 commit ecd1d7b

File tree

3 files changed

+49
-49
lines changed

3 files changed

+49
-49
lines changed

app/views/collections/_form.html.slim

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
- append_javascript_pack_tag('toast-ui')
33
- append_stylesheet_pack_tag('toast-ui')
44

5-
= form_for @collection, builder: MarkdownFormBuilder, data: {turbo: false} do |f|
6-
.my-4
5+
.my-4
6+
= form_for @collection, builder: MarkdownFormBuilder, data: {turbo: false}, id: 'edit_collection' do |f|
77
= render('shared/form_errors', object: @collection)
88
.form-group
99
.field-element
@@ -46,15 +46,15 @@
4646
i.fa-solid.fa-xmark.vert-align.text-danger.lead
4747

4848
br
49-
.form-group
50-
.actions.btn-group role='group'
51-
= button_tag type: 'submit', class: 'btn btn-important' do
52-
i.fa-solid.fa-folder-open
53-
=< t('.button.save')
54-
- if @collection.tasks.present?
55-
= button_to(remove_all_collection_path(@collection), method: :patch, data: {confirm: t('common.sure')}, class: 'btn btn-important h-100') do
56-
i.fa-solid.fa-xmark.text-danger
57-
=< t('.button.remove_all')
58-
= link_to(:back, class: 'btn btn-important') do
59-
i.fa-solid.fa-xmark
60-
=< t('common.button.cancel')
49+
.form-group
50+
.actions.btn-group role='group'
51+
= button_tag type: 'submit', class: 'btn btn-important', form: 'edit_collection' do
52+
i.fa-solid.fa-folder-open
53+
=< t('.button.save')
54+
- if @collection.tasks.present?
55+
= button_to(remove_all_collection_path(@collection), method: :patch, data: {confirm: t('common.sure')}, class: 'btn btn-important h-100') do
56+
i.fa-solid.fa-xmark.text-danger
57+
=< t('.button.remove_all')
58+
= link_to(:back, class: 'btn btn-important') do
59+
i.fa-solid.fa-xmark
60+
=< t('common.button.cancel')

app/views/comments/_edit.html.slim

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
= form_for :comment, url: task_comment_path(@task, @comment), method: :put, remote: true do |f|
2-
.comment-text
3-
.comment-text-input
1+
.comment-text
2+
.comment-text-input
3+
= form_for :comment, url: task_comment_path(@task, @comment), method: :put, remote: true, id: "edit_comment_#{@comment.id}", class: 'd-inline' do |f|
44
= f.text_field :text, class: 'form-control'
5-
.actions.btn-group.float-end role='group'
6-
- if policy(@comment).edit?
7-
= button_tag type: 'submit', class: 'btn btn-light btn-sm' do
8-
i.fa-solid.fa-floppy-disk
9-
=< t('common.button.save')
10-
= button_to(task_comment_path(@task, @comment), class: 'btn btn-light btn-sm', method: :delete, remote: true, data: {confirm: t('common.sure')})
11-
i.fa-solid.fa-trash-can
12-
=< t('common.button.delete')
5+
.actions.btn-group.float-end role='group'
6+
- if policy(@comment).edit?
7+
= button_tag type: 'submit', class: 'btn btn-light btn-sm', form: "edit_comment_#{@comment.id}" do
8+
i.fa-solid.fa-floppy-disk
9+
=< t('common.button.save')
10+
= button_to(task_comment_path(@task, @comment), class: 'btn btn-light btn-sm', method: :delete, remote: true, data: {confirm: t('common.sure')})
11+
i.fa-solid.fa-trash-can
12+
=< t('common.button.delete')

app/views/users/registrations/edit.html.slim

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
=< t('devise.registrations.edit.title', resource: User.model_name.human)
77

88
.row.my-4
9-
= form_for(resource, as: resource_name, url: registration_path(resource_name), html: {method: :put}) do |f|
9+
= form_for(resource, as: resource_name, url: registration_path(resource_name), html: {method: :put}, id: 'edit_user') do |f|
1010
= render('shared/form_errors', object: resource, title: t('common.errors.changes_not_saved'))
1111

1212
.form-group.field-element
@@ -74,27 +74,27 @@
7474
small.form-text.text-body-secondary = t('devise.registrations.edit.we_need_your_current_password_to_confirm_your_changes')
7575

7676

77-
- if devise_mapping.omniauthable? && resource_class.omniauth_providers.any?
78-
.form-group.field-element
79-
.form-label
80-
= t('.manage_omniauth')
81-
.form-content.manage_omniauth
82-
- resource_class.omniauth_providers.each do |provider|
83-
- provider_name = OmniAuth::Utils.camelize(provider)
84-
- configured_providers = current_user.omniauth_identities.pluck(:omniauth_provider)
85-
- if configured_providers.include?(provider.to_s) && (configured_providers.size > 1 || resource.password_set?)
86-
= button_to(t('.remove_identity', kind: provider_name), omniauth_deauthorize_path(provider), class: 'btn btn-light btn-sm mb-2 me-2', method: :delete)
87-
- elsif configured_providers.include?(provider.to_s)
88-
a.btn.btn-light.btn-sm.mb-2.me-2.disabled href='#'
89-
= t('.cannot_remove_last_identity', kind: provider_name)
90-
- else
91-
= button_to(t('.add_identity', kind: provider_name), omniauth_authorize_path(resource_name, provider), class: 'btn btn-light btn-sm mb-2 me-2', method: :post)
77+
- if devise_mapping.omniauthable? && resource_class.omniauth_providers.any?
78+
.form-group.field-element.px-4
79+
.form-label
80+
= t('.manage_omniauth')
81+
.form-content.manage_omniauth
82+
- resource_class.omniauth_providers.each do |provider|
83+
- provider_name = OmniAuth::Utils.camelize(provider)
84+
- configured_providers = current_user.omniauth_identities.pluck(:omniauth_provider)
85+
- if configured_providers.include?(provider.to_s) && (configured_providers.size > 1 || resource.password_set?)
86+
= button_to(t('.remove_identity', kind: provider_name), omniauth_deauthorize_path(provider), class: 'btn btn-light btn-sm mb-2 me-2', method: :delete)
87+
- elsif configured_providers.include?(provider.to_s)
88+
a.btn.btn-light.btn-sm.mb-2.me-2.disabled href='#'
89+
= t('.cannot_remove_last_identity', kind: provider_name)
90+
- else
91+
= button_to(t('.add_identity', kind: provider_name), omniauth_authorize_path(resource_name, provider), class: 'btn btn-light btn-sm mb-2 me-2', method: :post)
9292

93-
.form-group.py-3
94-
.btn-group role='group'
95-
= button_tag type: 'submit', class: 'btn btn-important' do
96-
i.fa-solid.fa-user
97-
=< t('common.button.update')
98-
= link_to(:back, class: 'btn btn-important') do
99-
i.fa-solid.fa-xmark.text-secondary
100-
=< t('common.button.back')
93+
.form-group.py-3
94+
.btn-group role='group'
95+
= button_tag type: 'submit', class: 'btn btn-important', form: 'edit_user' do
96+
i.fa-solid.fa-user
97+
=< t('common.button.update')
98+
= link_to(:back, class: 'btn btn-important') do
99+
i.fa-solid.fa-xmark.text-secondary
100+
=< t('common.button.back')

0 commit comments

Comments
 (0)