Class: Phlexi::Form::Components::InputArray

Inherits:
Base
  • Object
show all
Includes:
Concerns::HandlesArrayInput, Concerns::HandlesInput
Defined in:
lib/phlexi/form/components/input_array.rb

Instance Attribute Summary

Attributes inherited from Base

#attributes, #field

Instance Method Summary collapse

Methods included from Concerns::ExtractsInput

#extract_input

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Phlexi::Form::Components::Base

Instance Method Details

#view_templateObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/phlexi/form/components/input_array.rb', line 10

def view_template
  div(**attributes.slice(:id, :class)) do
    field.repeated(values.length) do |builder|
      render builder.hidden_field_tag if builder.index == 0

      field = builder.field(
        label: builder.key,
        # we expect key to be an integer string starting from "1"
        value: values[builder.index]
      )
      if block_given?
        yield field
      else
        render field.input_tag
      end
    end
  end
end