class Para::Inputs::NestedBaseInput
Constants
- GLOBAL_NESTED_FIELD_KEY
Private Instance Methods
dom_identifier()
click to toggle source
# File lib/para/inputs/nested_base_input.rb, line 8 def dom_identifier @dom_identifier ||= begin name = attribute_name id = @builder.object.id || "_new_#{parent_nested_field&.attribute_name}_" time = (Time.now.to_f * 1000).to_i random = (rand * 1000).to_i [name, id, time, random].join('-') end end
parent_nested_field(fallback_to_self: true)
click to toggle source
# File lib/para/inputs/nested_base_input.rb, line 47 def parent_nested_field(fallback_to_self: true) @parent_nested_field || (RequestStore.store[GLOBAL_NESTED_FIELD_KEY] if fallback_to_self) end
subclass()
click to toggle source
# File lib/para/inputs/nested_base_input.rb, line 18 def subclass @subclass ||= options.fetch(:subclass, subclasses.presence) end
subclasses()
click to toggle source
# File lib/para/inputs/nested_base_input.rb, line 22 def subclasses options.fetch(:subclasses, []) end
with_global_nested_field(&block)
click to toggle source
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.
# File lib/para/inputs/nested_base_input.rb, line 38 def with_global_nested_field(&block) @parent_nested_field = RequestStore.store[GLOBAL_NESTED_FIELD_KEY] RequestStore.store[GLOBAL_NESTED_FIELD_KEY] = self block.call ensure RequestStore.store[GLOBAL_NESTED_FIELD_KEY] = @parent_nested_field end