class Matestack::Ui::VueJs::Components::Form::Form

Attributes

prototype_template[RW]

Public Class Methods

new(html_tag = nil, text = nil, options = {}, &block) click to toggle source

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

Calls superclass method Matestack::Ui::VueJs::Vue::new
# File lib/matestack/ui/vue_js/components/form/form.rb, line 15
def initialize(html_tag = nil, text = nil, options = {}, &block)
  previous_form_context = Matestack::Ui::VueJs::Components::Form::Context.form_context
  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

Public Instance Methods

attributes() click to toggle source
# File lib/matestack/ui/vue_js/components/form/form.rb, line 40
def attributes
  {
    class: 'matestack-form',
    'v-bind:class': "{ 'has-errors': hasErrors(), loading: loading }",
    '@submit.prevent': 'perform',
  }
end
component_id() click to toggle source
# File lib/matestack/ui/vue_js/components/form/form.rb, line 22
def component_id
  "matestack-form-fields-for-#{context.fields_for}-#{SecureRandom.hex}" if context.fields_for
end
for_attribute() click to toggle source
# File lib/matestack/ui/vue_js/components/form/form.rb, line 63
def for_attribute
  return for_option.model_name.singular if for_option.respond_to?(:model_name)
  for_option
end
for_object_primary_key() click to toggle source
# File lib/matestack/ui/vue_js/components/form/form.rb, line 72
def for_object_primary_key
  context.for&.class&.primary_key rescue nil
end
for_option() click to toggle source
# File lib/matestack/ui/vue_js/components/form/form.rb, line 68
def for_option
  @for_option ||= ctx.for
end
form_method() click to toggle source
# File lib/matestack/ui/vue_js/components/form/form.rb, line 76
def form_method
  @form_method ||= options.delete(:method)
end
response() { || ... } click to toggle source
# File lib/matestack/ui/vue_js/components/form/form.rb, line 26
def response
  if context.fields_for
    div class: "matestack-form-fields-for", "v-show": "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
  else
    form attributes do
      yield
    end
  end
end
vue_props() click to toggle source
# File lib/matestack/ui/vue_js/components/form/form.rb, line 48
def vue_props
  {
    for: for_attribute,
    submit_path: ctx.path,
    method: form_method,
    success: ctx.success,
    failure: ctx.failure,
    multipart: !!ctx.multipart,
    emit: ctx.emit,
    delay: ctx.delay,
    fields_for: ctx.fields_for,
    primary_key: for_object_primary_key
  }
end