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

Public Instance Methods

attribute_key() click to toggle source
# File lib/matestack/ui/vue_js/components/form/base.rb, line 69
def attribute_key
  key.to_s + "#{'[]' if ctx.multiple && ctx.type == :file}"
end
attributes() click to toggle source

calculated attributes

# File lib/matestack/ui/vue_js/components/form/base.rb, line 54
def attributes
  (options || {}).merge({
    ref: "input.#{attribute_key}",
    ":id": id,
    type: ctx.type,
    multiple: ctx.multiple,
    placeholder: ctx.placeholder,
    '@change': change_event,
    'init-value': init_value,
    'v-bind:class': "{ '#{input_error_class}': #{error_key} }",
  }).tap do |attrs|
    attrs[:"#{v_model_type}"] = input_key unless type == :file
  end
end
change_event() click to toggle source
# File lib/matestack/ui/vue_js/components/form/base.rb, line 84
def change_event
  input_changed = "inputChanged('#{attribute_key}');"
  input_changed << "filesAdded('#{attribute_key}');" if type == :file
  input_changed
end
display_errors?() click to toggle source

error rendering

# File lib/matestack/ui/vue_js/components/form/base.rb, line 114
def display_errors?
  if form_context.ctx.errors == false
    error_config ? true : false
  else
    error_config != false
  end
end
error_class() click to toggle source
# File lib/matestack/ui/vue_js/components/form/base.rb, line 126
def error_class
  get_from_error_config(:class) || 'error'
end
error_config() click to toggle source
# File lib/matestack/ui/vue_js/components/form/base.rb, line 32
def error_config
  ctx.errors
end
error_key() click to toggle source
# File lib/matestack/ui/vue_js/components/form/base.rb, line 122
def error_key
  "$parent.errors['#{key}']"
end
error_tag() click to toggle source
# File lib/matestack/ui/vue_js/components/form/base.rb, line 130
def error_tag
  get_from_error_config(:tag) || :div
  # error_config.is_a?(Hash) && error_config.dig(:tag) || :div
end
form_context() click to toggle source
# File lib/matestack/ui/vue_js/components/form/base.rb, line 10
def form_context
  Matestack::Ui::VueJs::Components::Form::Context.form_context
end
get_from_error_config(*keys) click to toggle source
# File lib/matestack/ui/vue_js/components/form/base.rb, line 150
def get_from_error_config(*keys)
  comp_error_config = error_config.dig(*keys) if error_config.is_a?(Hash)
  form_error_config = form_context.ctx.errors.dig(*keys) if form_context.ctx.errors.is_a?(Hash)
  comp_error_config || form_error_config
end
id() click to toggle source
# File lib/matestack/ui/vue_js/components/form/base.rb, line 36
def id
  if ctx.id.present?
    "'#{ctx.id}'"
  else
    "'#{key}'+$parent.nestedFormRuntimeId"
  end
end
init() click to toggle source
# File lib/matestack/ui/vue_js/components/form/base.rb, line 28
def init
  ctx.init
end
init_value() click to toggle source
# File lib/matestack/ui/vue_js/components/form/base.rb, line 77
def init_value
  return init unless init.nil?
  if form_context.for_option.respond_to?(key)
    form_context.for_option.send(key)
  end
end
input_error_class() click to toggle source
# File lib/matestack/ui/vue_js/components/form/base.rb, line 135
def input_error_class
  get_from_error_config(:input, :class) || 'error'
  # error_config.is_a?(Hash) && error_config.dig(:input, :class) || 'error'
end
input_key() click to toggle source
# File lib/matestack/ui/vue_js/components/form/base.rb, line 90
def input_key
  "$parent.data['#{key}']"
end
input_label() click to toggle source
# File lib/matestack/ui/vue_js/components/form/base.rb, line 24
def input_label
  ctx.label
end
key() click to toggle source

options/settings

# File lib/matestack/ui/vue_js/components/form/base.rb, line 16
def key
  ctx.key
end
multiple() click to toggle source
# File lib/matestack/ui/vue_js/components/form/base.rb, line 44
def multiple
  ctx.multiple
end
name() click to toggle source
# File lib/matestack/ui/vue_js/components/form/base.rb, line 73
def name
  attribute_key
end
placeholder() click to toggle source
# File lib/matestack/ui/vue_js/components/form/base.rb, line 48
def placeholder
  ctx.placeholder
end
render_errors() click to toggle source
# File lib/matestack/ui/vue_js/components/form/base.rb, line 156
def render_errors
  if display_errors?
    Matestack::Ui::Component.new(wrapper_tag, class: wrapper_error_class, 'v-if': error_key) do
      Matestack::Ui::Component.new(error_tag, class: error_class, 'v-for': "error in #{error_key}") do
        plain vue.error
      end
    end
  end
end
type() click to toggle source
# File lib/matestack/ui/vue_js/components/form/base.rb, line 20
def type
  ctx.type
end
v_model_type(item=nil) click to toggle source

set v-model.number for all numeric init values or options

# File lib/matestack/ui/vue_js/components/form/base.rb, line 95
def v_model_type(item=nil)
  if item.nil?
    (type == :number || init_value.is_a?(Numeric)) ? 'v-model.number' : 'v-model'
  else
    item.is_a?(Integer) ? 'v-model.number' : 'v-model'
  end
end
value_type(item=nil) click to toggle source

set value-type “Integer” for all numeric init values or options

# File lib/matestack/ui/vue_js/components/form/base.rb, line 104
def value_type(item=nil)
  if item.nil?
    (type == :number || init_value.is_a?(Numeric)) ? Integer : nil
  else
    item.is_a?(Integer)? Integer : nil
  end
end
wrapper_error_class() click to toggle source
# File lib/matestack/ui/vue_js/components/form/base.rb, line 145
def wrapper_error_class
  get_from_error_config(:wrapper, :class) || 'errors'
  # error_config.is_a?(Hash) && error_config.dig(:wrapper, :class) || 'errors'
end
wrapper_tag() click to toggle source
# File lib/matestack/ui/vue_js/components/form/base.rb, line 140
def wrapper_tag
  get_from_error_config(:wrapper, :tag) || :div
  # error_config.is_a?(Hash) && error_config.dig(:wrapper, :tag) || :div
end