Class: FieldableForm::DropDown

Inherits:
Field
  • Object
show all
Defined in:
lib/fieldable_form/drop_down.rb

Constant Summary

Constants inherited from Field

Field::DESCENDANTS

Instance Method Summary collapse

Methods inherited from Field

new

Instance Method Details

#include_blankObject



42
43
44
# File 'lib/fieldable_form/drop_down.rb', line 42

def include_blank
  options['include_blank']
end

#include_blank=(value) ⇒ Object



46
47
48
49
# File 'lib/fieldable_form/drop_down.rb', line 46

def include_blank=(value)
  options_will_change! if options['include_blank'] != value
  options['include_blank'] = value
end

#itemsObject



51
52
53
# File 'lib/fieldable_form/drop_down.rb', line 51

def items
  options['items']
end

#items=(value) ⇒ Object



55
56
57
58
# File 'lib/fieldable_form/drop_down.rb', line 55

def items=(value)
  options_will_change! if options['items'] != value
  options['items'] = value
end

#render_methodObject

Overrides



7
8
9
# File 'lib/fieldable_form/drop_down.rb', line 7

def render_method
  :select
end

#render_optionsObject

Overrides



12
13
14
15
16
17
18
19
# File 'lib/fieldable_form/drop_down.rb', line 12

def render_options
  items_array = items.split(',').map(&:strip)
  if include_blank == '1'
    items_array.map! { |i| [i, i] }
    items_array.first[1] = nil
  end
  [name, items_array]
end

#requiredObject



33
34
35
# File 'lib/fieldable_form/drop_down.rb', line 33

def required
  options['required']
end

#required=(value) ⇒ Object



37
38
39
40
# File 'lib/fieldable_form/drop_down.rb', line 37

def required=(value)
  options_will_change! if options['required'] != value
  options['required'] = value
end

#validatorsObject

Overrides



27
28
29
30
31
# File 'lib/fieldable_form/drop_down.rb', line 27

def validators
  validators = []
  validators << ActiveModel::Validations::PresenceValidator.new(:attributes => name) if required == '1'
  validators
end

#view_partial_nameObject

Overrides



22
23
24
# File 'lib/fieldable_form/drop_down.rb', line 22

def view_partial_name
  'drop_down'
end