From 593e24e4b36a1791c8b506807e34167a9b24c14d Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Mon, 9 Aug 2021 21:06:53 +0200 Subject: [PATCH] Fix dom ids of ingredient editors These editors need a unique dom id to work correctly with their js events. --- app/views/alchemy/ingredients/_file_editor.html.erb | 4 +++- app/views/alchemy/ingredients/_link_editor.html.erb | 2 +- app/views/alchemy/ingredients/_node_editor.html.erb | 1 + app/views/alchemy/ingredients/_page_editor.html.erb | 1 + app/views/alchemy/ingredients/_picture_editor.html.erb | 1 + spec/helpers/alchemy/admin/ingredients_helper_spec.rb | 4 ++-- 6 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/views/alchemy/ingredients/_file_editor.html.erb b/app/views/alchemy/ingredients/_file_editor.html.erb index 793938aea5..ff3a9f846d 100644 --- a/app/views/alchemy/ingredients/_file_editor.html.erb +++ b/app/views/alchemy/ingredients/_file_editor.html.erb @@ -44,7 +44,9 @@ }, title: Alchemy.t(:edit_file_properties) %> - <%= f.hidden_field :attachment_id, value: file_editor.attachment&.id %> + <%= f.hidden_field :attachment_id, + value: file_editor.attachment&.id, + id: file_editor.form_field_id(:attachment_id) %> <% end %> <% end %> diff --git a/app/views/alchemy/ingredients/_link_editor.html.erb b/app/views/alchemy/ingredients/_link_editor.html.erb index 0427f45464..a82a5b1dda 100644 --- a/app/views/alchemy/ingredients/_link_editor.html.erb +++ b/app/views/alchemy/ingredients/_link_editor.html.erb @@ -6,7 +6,7 @@ <%= f.text_field :value, class: "thin_border text_with_icon disabled", name: nil, - id: nil, + id: link_editor.form_field_id, disabled: true %> <%= f.hidden_field :value, "data-link-value": true %> diff --git a/app/views/alchemy/ingredients/_node_editor.html.erb b/app/views/alchemy/ingredients/_node_editor.html.erb index 5d9bdacfab..26e8a12ebc 100644 --- a/app/views/alchemy/ingredients/_node_editor.html.erb +++ b/app/views/alchemy/ingredients/_node_editor.html.erb @@ -5,6 +5,7 @@ <%= ingredient_label(node_editor, :node_id) %> <%= f.text_field :node_id, value: node_editor.node&.id, + id: node_editor.form_field_id(:node_id), class: 'alchemy_selectbox full_width' %> <% end %> <% end %> diff --git a/app/views/alchemy/ingredients/_page_editor.html.erb b/app/views/alchemy/ingredients/_page_editor.html.erb index b3fde2f273..99049ef698 100644 --- a/app/views/alchemy/ingredients/_page_editor.html.erb +++ b/app/views/alchemy/ingredients/_page_editor.html.erb @@ -5,6 +5,7 @@ <%= ingredient_label(page_editor, :page_id) %> <%= f.text_field :page_id, value: page_editor.page&.id, + id: page_editor.form_field_id(:page_id), class: 'alchemy_selectbox full_width' %> <% end %> <% end %> diff --git a/app/views/alchemy/ingredients/_picture_editor.html.erb b/app/views/alchemy/ingredients/_picture_editor.html.erb index 2ed11e315f..4e58152644 100644 --- a/app/views/alchemy/ingredients/_picture_editor.html.erb +++ b/app/views/alchemy/ingredients/_picture_editor.html.erb @@ -44,6 +44,7 @@ <% end %> <%= f.hidden_field :picture_id, value: picture_editor.picture&.id, + id: picture_editor.form_field_id(:picture_id), data: { picture_id: true, image_file_width: picture_editor.image_file_width, diff --git a/spec/helpers/alchemy/admin/ingredients_helper_spec.rb b/spec/helpers/alchemy/admin/ingredients_helper_spec.rb index 4ccc5c6f39..cff0000a47 100644 --- a/spec/helpers/alchemy/admin/ingredients_helper_spec.rb +++ b/spec/helpers/alchemy/admin/ingredients_helper_spec.rb @@ -11,14 +11,14 @@ subject { helper.ingredient_label(ingredient_editor) } it "has for attribute set to ingredient form field id" do - is_expected.to have_selector('label[for="element_ingredients_attributes_0_value"]') + is_expected.to have_selector("label[for='element_#{element.id}_ingredient_#{ingredient.id}_value']") end context "with another column given" do subject { helper.ingredient_label(ingredient_editor, :picture_id) } it "has for attribute set to ingredient form field id for that column" do - is_expected.to have_selector('label[for="element_ingredients_attributes_0_picture_id"]') + is_expected.to have_selector("label[for='element_#{element.id}_ingredient_#{ingredient.id}_picture_id']") end end