diff --git a/app/components/tag_list_input_component.rb b/app/components/tag_list_input_component.rb index 259794fcfc..b8da0371d7 100644 --- a/app/components/tag_list_input_component.rb +++ b/app/components/tag_list_input_component.rb @@ -1,16 +1,14 @@ # frozen_string_literal: true class TagListInputComponent < ViewComponent::Base - # method in a "hidden_field" form helper and is the method used to get a list of tag on the model - def initialize(form:, method:, tags:, + def initialize(name:, tags:, placeholder: I18n.t("components.tag_list_input.default_placeholder"), aria_label: nil) - @f = form - @method = method + @name = name @tags = tags @placeholder = placeholder @aria_label_option = aria_label ? { 'aria-label': aria_label } : {} end - attr_reader :f, :method, :tags, :placeholder, :aria_label_option + attr_reader :name, :tags, :placeholder, :aria_label_option end diff --git a/app/components/tag_list_input_component/tag_list_input_component.html.haml b/app/components/tag_list_input_component/tag_list_input_component.html.haml index df6e5c57fd..9a139a963b 100644 --- a/app/components/tag_list_input_component/tag_list_input_component.html.haml +++ b/app/components/tag_list_input_component/tag_list_input_component.html.haml @@ -2,7 +2,7 @@ .tags-input .tags - # We use display:none instead of hidden field, so changes to the value can be picked up by the bulkFormController - = f.text_field method.to_sym, value: tags.join(","), "data-tag-list-input-target": "tagList", "style": "display: none" + = text_field_tag name, tags.join(","), {"data-tag-list-input-target": "tagList", "style": "display: none"} %ul.tag-list{"data-tag-list-input-target": "list"} %template{"data-tag-list-input-target": "template"} %li.tag-item @@ -16,4 +16,4 @@ %span=tag %a.remove-button{ "data-action": "click->tag-list-input#removeTag" } × - = text_field_tag "variant_add_tag_#{f.object.id}".to_sym, nil, class: "input", placeholder: placeholder, "data-action": "keydown.enter->tag-list-input#addTag keyup->tag-list-input#filterInput", "data-tag-list-input-target": "newTag", **aria_label_option + = text_field_tag "variant_add_tag", nil, class: "input", placeholder: placeholder, "data-action": "keydown.enter->tag-list-input#addTag keyup->tag-list-input#filterInput", "data-tag-list-input-target": "newTag", **aria_label_option diff --git a/app/views/admin/products_v3/_product_variant_row.html.haml b/app/views/admin/products_v3/_product_variant_row.html.haml index f5144fe7d7..f49c756078 100644 --- a/app/views/admin/products_v3/_product_variant_row.html.haml +++ b/app/views/admin/products_v3/_product_variant_row.html.haml @@ -7,7 +7,7 @@ = render partial: 'product_row', locals: { f: product_form, product:, product_index: } - product.variants.each_with_index do |variant, variant_index| - = form.fields_for("products][#{product_index}][variants_attributes][", variant, index: variant_index) do |variant_form| + = form.fields_for("products][#{product_index}][variants_attributes", variant, index: variant_index) do |variant_form| %tr.condensed{ id: dom_id(variant), 'data-controller': "variant", 'class': "nested-form-wrapper", 'data-new-record': variant.new_record? ? "true" : false } = render partial: 'variant_row', locals: { variant:, f: variant_form, category_options:, tax_category_options:, producer_options: } diff --git a/app/views/admin/products_v3/_variant_row.html.haml b/app/views/admin/products_v3/_variant_row.html.haml index d5aa876e46..4235c69a11 100644 --- a/app/views/admin/products_v3/_variant_row.html.haml +++ b/app/views/admin/products_v3/_variant_row.html.haml @@ -80,7 +80,7 @@ = error_message_on variant, :tax_category - if feature?(:variant_tag, spree_current_user) %td.col-tags.field.naked_inputs - = render TagListInputComponent.new(form: f, method: "tag_list", tags: variant.tag_list, placeholder: t('.add_a_tag'), aria_label: t('admin.products_page.columns.tags')) + = render TagListInputComponent.new(name: f.field_name(:tag_list), tags: variant.tag_list, placeholder: t('.add_a_tag'), aria_label: t('admin.products_page.columns.tags')) %td.col-inherits_properties.align-left -# empty %td.align-right diff --git a/spec/system/admin/product_import_spec.rb b/spec/system/admin/product_import_spec.rb index aa8757ca59..46e484fc14 100644 --- a/spec/system/admin/product_import_spec.rb +++ b/spec/system/admin/product_import_spec.rb @@ -672,7 +672,7 @@ RSpec.describe "Product Import" do within "#product_#{carrots.id}" do expect(page).to have_input("[products][2][variants_attributes][0][display_name]", text: "Carrots") - expect(page).to have_input("[products][2][variants_attributes][][0][unit_to_display]", + expect(page).to have_input("[products][2][variants_attributes][0][unit_to_display]", text: "1 lb") within(:xpath, '//*[@id="products-form"]/table/tbody[3]/tr[2]/td[7]') do expect(page).to have_content("5")