Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bonner Cohort Invite #1295

Open
Mbeweg opened this issue Jul 23, 2024 · 1 comment · May be fixed by #1297
Open

Bonner Cohort Invite #1295

Mbeweg opened this issue Jul 23, 2024 · 1 comment · May be fixed by #1297
Assignees

Comments

@Mbeweg
Copy link
Contributor

Mbeweg commented Jul 23, 2024

In the Bonner training event, the selected/invited cohort does not stay checked.
image
image

@Mbeweg
Copy link
Contributor Author

Mbeweg commented Jul 25, 2024

We worked on the cohort checkboxes. Using the createEvents.js file, we added a new function that enables the checkbox of the selected cohort to remain checked when saved. To ensure that cohort checkboxes remain checked even after the page is refreshed we used the saveSelectedCohorts function to collect the values of all checked checkboxes and store them in localStorage whenever a checkbox changes. The loadSelectedCohorts function retrieves these values from localStorage and checks the corresponding checkboxes when the page loads. By attaching the saveSelectedCohorts function to the change event of the checkboxes and calling loadSelectedCohorts when the document is ready, the code maintains the state of the checkboxes across page reloads. This is the code below;

function saveSelectedCohorts() {
  const selectedCohorts = [];
  $("input[name='cohorts[]']:checked").each(function () {
    selectedCohorts.push($(this).val());
  });
  localStorage.setItem("selectedCohorts", JSON.stringify(selectedCohorts));
}

// Attach the change event to all cohort checkboxes
$(document).on("change", "input[name='cohorts[]']", saveSelectedCohorts);

function loadSelectedCohorts() {
  const selectedCohorts = JSON.parse(localStorage.getItem("selectedCohorts")) || [];
  selectedCohorts.forEach(function (year) {
    $(`input[name='cohorts[]'][value='${year}']`).prop("checked", true);
  }); ``

@bledsoef bledsoef linked a pull request Sep 6, 2024 that will close this issue
@bledsoef bledsoef linked a pull request Sep 6, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants