introduce check_other and radio_other question types
completes issue #48
This commit is contained in:
@@ -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."
|
||||
|
Reference in New Issue
Block a user