mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
TagListInputComponent removed dependency on the form
This allows us to use the component in a context where there is no form object defined.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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: }
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user