Class: Rapidfire::Questions::Checkbox

Inherits:
Rapidfire::Question show all
Defined in:
app/models/rapidfire/questions/checkbox.rb

Instance Method Summary collapse

Methods inherited from Rapidfire::Question

inherited, #rules

Instance Method Details

#optionsObject



6
7
8
# File 'app/models/rapidfire/questions/checkbox.rb', line 6

def options
  answer_options.split(/\r?\n/)
end

#validate_answer(answer) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'app/models/rapidfire/questions/checkbox.rb', line 10

def validate_answer(answer)
  super(answer)

  if rules[:presence] == "1" || answer.answer_text.present?
    answer.answer_text.split(",").each do |value|
      answer.errors.add(:answer_text, :invalid) unless options.include?(value)
    end
  end
end