Class: FactoryForm::MultipleChoice

Inherits:
Field
  • Object
show all
Defined in:
lib/factoryform/multiple_choice.rb

Constant Summary collapse

FIELD_TYPE =

attr_accessor :type # select_box, check_box, radio_button(:default)

["select_box", "check_box", "radio_button"]

Instance Attribute Summary collapse

Attributes inherited from Field

#field_type, #hint, #id, #label, #required, #unique, #validation_format

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ MultipleChoice

Returns a new instance of MultipleChoice.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/factoryform/multiple_choice.rb', line 7

def initialize(options={})
  options[:field_type] ||=  "radio_button"
  super(options)

  # Unique is always false
  @unique = false
  
  if options[:values] && options[:values].length > 1
    @values = options[:values]
  else
    raise(ParameterExpectedException, "Missing option values (at least two)")
  end
  
  
  check_field_type
end

Instance Attribute Details

#valuesObject

Option values



3
4
5
# File 'lib/factoryform/multiple_choice.rb', line 3

def values
  @values
end

Instance Method Details

#add_option(value) ⇒ Object



24
25
26
# File 'lib/factoryform/multiple_choice.rb', line 24

def add_option(value)
  @values.push(value)
end

#remove_option(value) ⇒ Object



28
29
30
# File 'lib/factoryform/multiple_choice.rb', line 28

def remove_option(value)
  @values.delete(value)
end