introduce check_other and radio_other question types

completes issue #48
This commit is contained in:
Mark Moser
2016-08-31 16:59:25 -05:00
parent 229ebf1380
commit df1b101aa2
12 changed files with 276 additions and 14 deletions

View File

@@ -38,8 +38,23 @@ class AnswerFormatValidator < ActiveModel::EachValidator
record.errors[attribute] << (options[:message] || live_code_error_message(value))
end
def with_other record, attribute, value
return if value.present? && with_other_check(value)
record.errors[attribute] << (options[:message] || "Please select or provide an answer.")
end
alias radio_other with_other
alias checkbox_other with_other
#################################
def with_other_check value
return false unless value.respond_to? :keys
return false if Array(value[:options]).join.blank?
return false if value[:options].include?('other') && value[:other].to_s.blank?
true
end
def live_code_error_message value
if value.present? && value.keys.count == 1
return "Please check that you will come back to complete the code example."