diff --git a/app/javascript/packs/schools.js b/app/javascript/packs/schools.js index 212f58bf..6bf8b345 100644 --- a/app/javascript/packs/schools.js +++ b/app/javascript/packs/schools.js @@ -40,7 +40,8 @@ let create_school = function (input, callback) { selectizeCallback = null; $('#teacher_school_id').val(original_school_id); } - toggle_required(['name', 'city', 'state', 'website'], true); + // TODO: This list should match the model attributes. + toggle_required(['name', 'city', 'state', 'website', 'grade_level', 'school_type'], true); $("#school_form").hide(); }); }; diff --git a/app/models/school.rb b/app/models/school.rb index 29966ddc..446febf5 100644 --- a/app/models/school.rb +++ b/app/models/school.rb @@ -32,8 +32,10 @@ class School < ApplicationRecord validates :state, presence: true, if: -> { country == "US" } validates :state, inclusion: { in: VALID_STATES }, if: -> { country == "US" } validates_format_of :website, with: /.+\..+/, on: :create + validates :grade_level, presence: true + validates :school_type, presence: true - before_save :update_gps_data, if: -> { lat.nil? || lng.nil? } + before_save :update_gps_data, if: -> { lat.nil? || lng.nil? || location_changed? } has_many :teachers scope :validated, -> { where("teachers_count > 0") } @@ -124,6 +126,10 @@ def self.all_maps_data end private + def location_changed? + city_changed? || state_changed? || country_changed? + end + def prefix_url(url) return unless url url.match?(/^https?:/) ? url : "https://#{url}"