Class: Formic::Input

Inherits:
Base
  • Object
show all
Defined in:
lib/formic/input.rb

Direct Known Subclasses

Checkbox, File, Hidden, Password, Selection, Textarea

Instance Attribute Summary collapse

Attributes inherited from Base

#content, #options, #page, #template

Instance Method Summary collapse

Methods inherited from Base

#add_class, default_template, #formics, #has_class?, #initialize, #merge_options, #method_missing, template, #to_s

Constructor Details

This class inherits a constructor from Formic::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Formic::Base

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field.



5
6
7
# File 'lib/formic/input.rb', line 5

def field
  @field
end

Instance Method Details

#_initialize(name = nil, options = {}, &block) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# 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

#formObject



33
34
35
36
37
38
39
# 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

#labelObject



7
8
9
10
# File 'lib/formic/input.rb', line 7

def label
  return self.options[:label] if self.options[:label]
  return @field.underscore.gsub('_', ' ').titleize
end