Sha256: 677b82d8f0427d0fd61d8e7433b9085f6c6db1c5cc7abca5c617a29260cfd9d8

Contents?: true

Size: 774 Bytes

Versions: 12

Compression:

Stored size: 774 Bytes

Contents

module Para
  module Inputs
    class NestedBaseInput < SimpleForm::Inputs::Base
      GLOBAL_NESTED_FIELD_KEY = "para.nested_field.parent"

      private

      # This allows to access the parent nested field from a child nested field
      # and fetch some of its data. This is useful for deeply nested cocoon
      # fields.
      #
      def with_global_nested_field(&block)
        @parent_nested_field = RequestStore.store[GLOBAL_NESTED_FIELD_KEY]
        RequestStore.store[GLOBAL_NESTED_FIELD_KEY] = self

        block.call.tap do
          RequestStore.store[GLOBAL_NESTED_FIELD_KEY] = @parent_nested_field
        end
      end

      def parent_nested_field
        @parent_nested_field || RequestStore.store[GLOBAL_NESTED_FIELD_KEY]
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
para-0.8.1 lib/para/inputs/nested_base_input.rb
para-0.8.0 lib/para/inputs/nested_base_input.rb
para-0.7.4.p1 lib/para/inputs/nested_base_input.rb
para-0.7.4 lib/para/inputs/nested_base_input.rb
para-0.7.3.p6 lib/para/inputs/nested_base_input.rb
para-0.7.3.p5 lib/para/inputs/nested_base_input.rb
para-0.7.3.p4 lib/para/inputs/nested_base_input.rb
para-0.7.3.p3 lib/para/inputs/nested_base_input.rb
para-0.7.3.p2 lib/para/inputs/nested_base_input.rb
para-0.7.3.p1 lib/para/inputs/nested_base_input.rb
para-0.7.3 lib/para/inputs/nested_base_input.rb
para-0.7.2 lib/para/inputs/nested_base_input.rb