Skip to content

Commit

Permalink
Fix validation for geojson in answer options
Browse files Browse the repository at this point in the history
  • Loading branch information
JoonasAapro committed Apr 8, 2024
1 parent 07eb5a4 commit 194be35
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ module AnswerOptionFormExtensions

included do
attribute :geojson, JSON

validates :geojson, presence: true, unless: :deleted
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,23 @@ module QuestionFormExtensions
attribute :default_latitude, Float, default: 0
attribute :default_longitude, Float, default: 0

validate :answer_option_location, if: :select_locations?

def map_locations?
question_type == "map_locations"
end

def select_locations?
question_type == "select_locations"
end

def answer_option_location
answer_options.each do |answer_option|
if answer_option.geojson.blank?
errors.add(:answer_options, :missing)
end
end
end
end
end
end
Expand Down

0 comments on commit 194be35

Please sign in to comment.