Sha256: 778434a2d3bdc75cfe81d1810aaa542e4a59a4939c6c26bbe93728dc5e8de2c4

Contents?: true

Size: 1.06 KB

Versions: 30

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

module Phlexi
  module Form
    module Structure
      class FieldCollection < Phlexi::Field::Structure::FieldCollection
        class Builder < Phlexi::Field::Structure::FieldCollection::Builder
          def field(**options)
            options = mix({input_attributes: @field.input_attributes}, options)
            @field.class.new(key, **options, parent: @field).tap do |field|
              yield field if block_given?
            end
          end

          def hidden_field_tag(value: "", force: false)
            raise "Attempting to build hidden field on non-first field in a collection" unless index == 0 || force

            @field.class
              .new("hidden", parent: @field)
              .input_tag(type: :hidden, value:)
          end
        end

        private

        def build_collection(collection)
          case collection
          when Range, Array
            collection
          when Integer
            1..collection
          else
            collection.to_a
          end
        end
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
phlexi-form-0.8.3 lib/phlexi/form/structure/field_collection.rb
phlexi-form-0.8.2 lib/phlexi/form/structure/field_collection.rb
phlexi-form-0.8.1 lib/phlexi/form/structure/field_collection.rb
phlexi-form-0.8.0 lib/phlexi/form/structure/field_collection.rb
phlexi-form-0.7.2 lib/phlexi/form/structure/field_collection.rb
phlexi-form-0.7.1 lib/phlexi/form/structure/field_collection.rb
phlexi-form-0.7.0 lib/phlexi/form/structure/field_collection.rb
phlexi-form-0.6.2 lib/phlexi/form/structure/field_collection.rb
phlexi-form-0.6.1 lib/phlexi/form/structure/field_collection.rb
phlexi-form-0.6.0 lib/phlexi/form/structure/field_collection.rb
phlexi-form-0.5.11 lib/phlexi/form/structure/field_collection.rb
phlexi-form-0.5.10 lib/phlexi/form/structure/field_collection.rb
phlexi-form-0.5.9 lib/phlexi/form/structure/field_collection.rb
phlexi-form-0.5.8 lib/phlexi/form/structure/field_collection.rb
phlexi-form-0.5.7 lib/phlexi/form/structure/field_collection.rb
phlexi-form-0.5.6 lib/phlexi/form/structure/field_collection.rb
phlexi-form-0.5.5 lib/phlexi/form/structure/field_collection.rb
phlexi-form-0.5.4 lib/phlexi/form/structure/field_collection.rb
phlexi-form-0.5.3 lib/phlexi/form/structure/field_collection.rb
phlexi-form-0.5.2 lib/phlexi/form/structure/field_collection.rb