live code validations working
This commit is contained in:
@ -6,31 +6,32 @@ class AnswerFormatValidator < ActiveModel::EachValidator
|
||||
private
|
||||
|
||||
def text record, attribute, value
|
||||
return unless value.length.between? 1, 1000
|
||||
clean_val = value.to_s.strip
|
||||
return if clean_val.length.between?(1, 1000)
|
||||
|
||||
if value.blank?
|
||||
if clean_val.blank?
|
||||
record.errors[attribute] << (options[:message] || "Please enter an answer.")
|
||||
end
|
||||
|
||||
if value.length > 1000
|
||||
if clean_val.length > 1000
|
||||
record.errors[attribute] << (options[:message] || "The character limit for a textarea answer is 1000")
|
||||
end
|
||||
end
|
||||
|
||||
def radio record, attribute, value
|
||||
return unless value.nil?
|
||||
return unless value.to_s.strip.blank?
|
||||
|
||||
record.errors[attribute] << (options[:message] || "Please select an answer.")
|
||||
end
|
||||
|
||||
def checkbox record, attribute, value
|
||||
return unless value.nil? || value.join.blank?
|
||||
return unless value.nil? || Array(value).join.blank?
|
||||
|
||||
record.errors[attribute] << (options[:message] || "Please select an answer.")
|
||||
end
|
||||
|
||||
def live_code record, attribute, value
|
||||
return unless value.nil?
|
||||
return unless value.nil? || value.values.join.blank?
|
||||
|
||||
msg = "You must write code in one of the above textareas to progress."
|
||||
record.errors[attribute] << (options[:message] || msg)
|
||||
|
@ -29,3 +29,5 @@
|
||||
# to check for JS capability/enabled
|
||||
%>
|
||||
</div>
|
||||
|
||||
<%= render partial: "candidate/answer_errors", locals: {question: question, answer: @answer} %>
|
||||
|
@ -13,6 +13,4 @@
|
||||
<%= text_area_tag 'answer[live_code][js]', (@answer['js'] unless @answer.nil?), { 'data-id' => 'code-js', class: 'code-answer code-js' } %>
|
||||
</div>
|
||||
|
||||
<%= render partial: "candidate/answer_errors", locals: {question: @question, answer: @answer} %>
|
||||
|
||||
<div class="results" data-id="results"></div>
|
||||
|
Reference in New Issue
Block a user