Skip to content

Commit

Permalink
more robust required toggles for school
Browse files Browse the repository at this point in the history
  • Loading branch information
cycomachead committed Aug 27, 2024
1 parent db0c1e8 commit fcb58d0
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions app/javascript/packs/schools.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ $("#new_school").on("submit", function (e) {
});
});

// TODO: This list should match the model attributes.
const SCHOOL_REQUIRED_ATTRIBUTES = ['name', 'city', 'state', 'website', 'grade_level', 'school_type'];

let toggle_required = (selectors, state) => {
selectors.forEach(s => $(`#school_${s}`).prop("required", state))
}

let create_school = function (input, callback) {
var selectizeCallback = callback;
$("#school_form").show();
toggle_required(['name', 'city', 'state', 'website'], true);
toggle_required(SCHOOL_REQUIRED_ATTRIBUTES, true);
$(".btn-primary").show();
let original_school_id = $('#teacher_school_id').val();
var reset_button = $("#close_button");
Expand All @@ -40,8 +43,7 @@ let create_school = function (input, callback) {
selectizeCallback = null;
$('#teacher_school_id').val(original_school_id);
}
// TODO: This list should match the model attributes.
toggle_required(['name', 'city', 'state', 'website', 'grade_level', 'school_type'], true);
toggle_required(SCHOOL_REQUIRED_ATTRIBUTES, true);
$("#school_form").hide();
});
};
Expand All @@ -55,5 +57,5 @@ let $school_selector = $(".select").selectize({
$school_selector.on('change', () => {
let selectedSchool = JSON.parse($("#school_selectize").val());
$('#teacher_school_id').val(selectedSchool.id);
toggle_required(['name', 'city', 'state', 'website'], false);
toggle_required(SCHOOL_REQUIRED_ATTRIBUTES, false);
});

0 comments on commit fcb58d0

Please sign in to comment.