Skip to content

Commit

Permalink
Move code to toggle college 'other' field to own file
Browse files Browse the repository at this point in the history
  • Loading branch information
Janell-Huyck committed Nov 16, 2023
1 parent 7daee10 commit 3cce329
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
31 changes: 1 addition & 30 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
//= require jquery3
//= require popper
//= require bootstrap-sprockets
//= require toggle_college_other_field

$(document).on('turbolinks:load', function() {
$('[data-toggle="tooltip"]').tooltip();
Expand Down Expand Up @@ -47,33 +48,3 @@ function addAuthor(type, count) {
function removeAuthor(idToDelete) {
document.getElementById(idToDelete).outerHTML = '';
}

$(document).on('turbolinks:load', function() {
if (window.location.pathname.includes("/edit") || window.location.pathname.includes("/new")) {
otherChkbox = document.querySelector('[id$="_college_ids_16"]');
otherField = document.querySelector('[id$="_other_college"]');
otherGroup = document.querySelector('[id$="other_college_group"]');
tempStorage = '';

if (otherField.value != "") {
otherChkbox.checked = true;
}
else {
otherGroup.classList.toggle("d-none");
}

otherChkbox.onclick = function() {
if (otherChkbox.checked) {
otherGroup.classList.toggle("d-none");
if (tempStorage != '') {
otherField.value = tempStorage;
}
}
else {
otherGroup.classList.toggle("d-none");
tempStorage = otherField.value;
otherField.value = '';
}
}
}
})
29 changes: 29 additions & 0 deletions app/assets/javascripts/toggle_college_other_field.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
$(document).on('turbolinks:load', function() {
if (window.location.pathname.includes("/edit") || window.location.pathname.includes("/new")) {
otherChkbox = document.querySelector('[id$="_college_ids_16"]');
otherField = document.querySelector('[id$="_other_college"]');
otherGroup = document.querySelector('[id$="other_college_group"]');
tempStorage = '';

if (otherField.value != "") {
otherChkbox.checked = true;
}
else {
otherGroup.classList.toggle("d-none");
}

otherChkbox.onclick = function() {
if (otherChkbox.checked) {
otherGroup.classList.toggle("d-none");
if (tempStorage != '') {
otherField.value = tempStorage;
}
}
else {
otherGroup.classList.toggle("d-none");
tempStorage = otherField.value;
otherField.value = '';
}
}
}
})

0 comments on commit 3cce329

Please sign in to comment.