Class: Para::Inputs::NestedManyInput

Inherits:
NestedBaseInput
  • Object
show all
Defined in:
lib/para/inputs/nested_many_input.rb

Constant Summary

Constants inherited from NestedBaseInput

Para::Inputs::NestedBaseInput::GLOBAL_NESTED_FIELD_KEY

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#resourceObject (readonly)

Returns the value of attribute resource.



4
5
6
# File 'lib/para/inputs/nested_many_input.rb', line 4

def resource
  @resource
end

Instance Method Details

#input(_wrapper_options = nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/para/inputs/nested_many_input.rb', line 6

def input(_wrapper_options = nil)
  input_html_options[:class] << 'nested-many'

  orderable = options.fetch(:orderable, model.orderable?)
  add_button = options.fetch(:add_button, true)
  # Load existing resources
  resources = object.send(attribute_name)
  # Order them if the list should be orderable
  resources = resources.sort_by(&:position) if orderable

  locals = options.fetch(:locals, {})

  with_global_nested_field do
    template.render(
      partial: 'para/inputs/nested_many',
      locals: {
        form: @builder,
        model: model,
        attribute_name: attribute_name,
        orderable: orderable,
        add_button: add_button,
        dom_identifier: dom_identifier,
        resources: resources,
        nested_locals: locals,
        subclass: subclass,
        subclasses: subclasses,
        add_button_label: add_button_label,
        add_button_class: add_button_class,
        inset: inset?,
        uncollapsed: uncollapsed?,
        render_partial: render_partial?,
        remote_partial_params: remote_partial_params
      }
    )
  end
end