Class: Matestack::Ui::VueJs::Components::Form::NestedForm

Inherits:
Form
  • Object
show all
Defined in:
lib/matestack/ui/vue_js/components/form/nested_form.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Form

#attributes, #for_attribute, #for_object_primary_key, #for_option, #form_method, #multipart_option

Methods inherited from Vue

#base_vue_props, #component_attributes, #component_uid, #create_children, inherited, #matestack_ui_vuejs_ref, #vue_component, vue_name, #vue_name

Constructor Details

#initialize(html_tag = nil, text = nil, options = {}, &block) ⇒ NestedForm

setup form context to allow child components like inputs to access the form configuration



14
15
16
17
18
19
20
21
22
23
# File 'lib/matestack/ui/vue_js/components/form/nested_form.rb', line 14

def initialize(html_tag = nil, text = nil, options = {}, &block)
  previous_form_context = Matestack::Ui::VueJs::Components::Form::Context.form_context
  if !previous_form_context.nil?
    @is_nested_form = true
    @parent_form_context = previous_form_context
  end
  Matestack::Ui::VueJs::Components::Form::Context.form_context = self
  super(html_tag, text, options, &block)
  Matestack::Ui::VueJs::Components::Form::Context.form_context = previous_form_context
end

Instance Attribute Details

#prototype_templateObject

Returns the value of attribute prototype_template.



11
12
13
# File 'lib/matestack/ui/vue_js/components/form/nested_form.rb', line 11

def prototype_template
  @prototype_template
end

Instance Method Details

#component_idObject



25
26
27
# File 'lib/matestack/ui/vue_js/components/form/nested_form.rb', line 25

def component_id
  "matestack-form-fields-for-#{context.fields_for}-#{SecureRandom.hex}"
end

#is_nested_form?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/matestack/ui/vue_js/components/form/nested_form.rb', line 44

def is_nested_form?
  true
end

#parent_form_contextObject



48
49
50
# File 'lib/matestack/ui/vue_js/components/form/nested_form.rb', line 48

def parent_form_context
  @parent_form_context
end

#responseObject



29
30
31
32
33
34
35
# File 'lib/matestack/ui/vue_js/components/form/nested_form.rb', line 29

def response
  div class: "matestack-form-fields-for", "v-show": "vc.hideNestedForm != true", id: options[:id] do
    form_input key: context.for&.class&.primary_key, type: :hidden # required for existing model mapping
    form_input key: :_destroy, type: :hidden, init: true if context.reject_blank == true
    yield
  end
end

#vue_propsObject



37
38
39
40
41
42
# File 'lib/matestack/ui/vue_js/components/form/nested_form.rb', line 37

def vue_props
  super.merge({
    fields_for: ctx.fields_for,
    primary_key: for_object_primary_key
  })
end