{% for section, institutions in institution_sections %}
{{ section.name }}:
-
+
{% for institution in institutions %}
{{ institution.name }}
{% endfor %}
{% endfor %}
From 6e612ea10ceecf40e702a832532e56ee7aa57cd5 Mon Sep 17 00:00:00 2001
From: CJ Green <44074998+okaycj@users.noreply.github.com>
Date: Tue, 7 Nov 2023 09:31:47 -0500
Subject: [PATCH 4/4] Replace inline onchange event
Also there was a misplaced "onemptied" on the option element.
---
web/static/js/study-detail-web.js | 31 +++++++++++++++++++----------
web/templates/web/study-detail.html | 8 +++-----
2 files changed, 23 insertions(+), 16 deletions(-)
diff --git a/web/static/js/study-detail-web.js b/web/static/js/study-detail-web.js
index b60057332..71bd29d8c 100644
--- a/web/static/js/study-detail-web.js
+++ b/web/static/js/study-detail-web.js
@@ -1,9 +1,6 @@
-$('.text-warning').hide();
-$("#child-dropdown").val("none");
-childSelected(document.getElementById('child-dropdown'));
-
-function childSelected(selectElement) {
- var participateButton = document.getElementById('participate-button');
+function childSelected() {
+ const selectElement = document.getElementById('child-dropdown');
+ const participateButton = document.getElementById('participate-button');
if (selectElement.value === 'none') {
participateButton.disabled = true;
document.getElementById('too-old').classList.add('d-none');
@@ -42,13 +39,13 @@ function calculateAgeInDays(birthday) {
function ageCheck(age) {
// Adapted from experiment model in exp-addons
- var minDays;
- var maxDays;
- var study_age_criteria = document.getElementById('child-dropdown').dataset;
+ let minDays;
+ let maxDays;
+ const study_age_criteria = document.getElementById('child-dropdown').dataset;
// These are now hard-coded to avoid unpredictable behavior from moment.duration().asDays()
// e.g. 1 year = 365 days, 1 month = 30 days, and 1 year + 1 month = 396 days.
- minDays = parseInt(study_age_criteria.studyMinAgeDays,10) + 30 * parseInt(study_age_criteria.studyMinAgeMonths,10) + 365 * parseInt(study_age_criteria.studyMinAgeYears,10);
- maxDays = parseInt(study_age_criteria.studyMaxAgeDays,10) + 30 * parseInt(study_age_criteria.studyMaxAgeMonths,10) + 365 * parseInt(study_age_criteria.studyMaxAgeYears,10);
+ minDays = parseInt(study_age_criteria.studyMinAgeDays, 10) + 30 * parseInt(study_age_criteria.studyMinAgeMonths, 10) + 365 * parseInt(study_age_criteria.studyMinAgeYears, 10);
+ maxDays = parseInt(study_age_criteria.studyMaxAgeDays, 10) + 30 * parseInt(study_age_criteria.studyMaxAgeMonths, 10) + 365 * parseInt(study_age_criteria.studyMaxAgeYears, 10);
minDays = minDays || -1;
maxDays = maxDays || Number.MAX_SAFE_INTEGER;
@@ -61,3 +58,15 @@ function ageCheck(age) {
return 0;
}
}
+
+/**
+ * On Page load
+ */
+$('.text-warning').hide();
+$("#child-dropdown").val("none");
+childSelected();
+
+/**
+ * Event listeners
+ */
+document.querySelector('#child-dropdown')?.addEventListener('change', childSelected)
diff --git a/web/templates/web/study-detail.html b/web/templates/web/study-detail.html
index b1691f366..98e47ad2f 100644
--- a/web/templates/web/study-detail.html
+++ b/web/templates/web/study-detail.html
@@ -109,13 +109,11 @@
{% trans "Would you like to participate in this study?" %}
data-study-min-age-years="{{ study.min_age_years }}"
data-study-max-age-days="{{ study.max_age_days }}"
data-study-max-age-months="{{ study.max_age_months }}"
- data-study-max-age-years="{{ study.max_age_years }}"
- onchange="childSelected(this)">
-
+ data-study-max-age-years="{{ study.max_age_years }}">
+
{% for child in children %}
{% child_is_valid_for_study_criteria child object as child_is_eligible %}
-