class Formic::Input

Attributes

field[R]

Public Instance Methods

_initialize(name=nil, options={}) click to toggle source
Calls superclass method Formic::Base#_initialize
# File lib/formic/input.rb, line 12
def _initialize name=nil, options={}, &block
  if name.instance_of? Hash
    options = name
    name = nil
  end

  super options, &block
  @field = name || options[:name]

  if !options[:name]
    if @field && self.form && self.form.model
      self.options[:name] = "#{self.form.model.class.to_s.downcase}[#{name}]"
      self.options[:value] ||= self.form.model.send(@field.to_sym)
    elsif
      self.options[:name] = name
    end
  end

  return self
end
form() click to toggle source
# File lib/formic/input.rb, line 33
def form
  self.formics.each do |element|
    return element if element.instance_of? Formic::Form
  end

  return nil
end
label() click to toggle source
# File lib/formic/input.rb, line 7
def label
  return self.options[:label] if self.options[:label]
  return @field.underscore.gsub('_', ' ').titleize
end