From 65afb91b6126fbf64496488b98f77c0e9cb7a352 Mon Sep 17 00:00:00 2001 From: Luis Aleixo Date: Tue, 27 Sep 2022 18:10:07 +0200 Subject: [PATCH] handled display errors --- caimira/apps/calculator/static/js/form.js | 19 ++++++++++++++----- .../templates/base/calculator.form.html.j2 | 6 +++--- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/caimira/apps/calculator/static/js/form.js b/caimira/apps/calculator/static/js/form.js index 5ce28dd1..68b08f4e 100644 --- a/caimira/apps/calculator/static/js/form.js +++ b/caimira/apps/calculator/static/js/form.js @@ -336,10 +336,15 @@ function update_booster_warning() { function update_booster_dropdown(url) { let primary_vaccine_option = $("#vaccine_type").find(":selected").val(); $($("#vaccine_booster_type > option").get().reverse()).each(function() { - if ($(this).attr('data-primary-vaccine') != primary_vaccine_option && $(this).val() != "Other") $(this).hide(); - else $(this).show().prop('selected', true); + if ($(this).attr('data-primary-vaccine') != primary_vaccine_option && $(this).attr('data-primary-vaccine') != "Other") $(this).hide(); + else { + $(this).show(); + if (url.searchParams.has('vaccine_type')) { + if (url.searchParams.get('vaccine_type') != primary_vaccine_option) $(this).prop('selected', true); // Select first of the list if not from the URL + } + else $(this).prop('selected', true); + } }); - if (url.searchParams.has('vaccine_booster_type')) $("#vaccine_booster_type").val(url.searchParams.get('vaccine_booster_type')); update_booster_warning(); } @@ -891,8 +896,8 @@ $(document).ready(function () { $("#sr_interactions").text(index - 1); } - else if (name == 'sensor_in_use') { - // TODO - Validate if sensor exists + else if (name == 'sensor_in_use' || name == 'vaccine_booster_type') { + // Validation after } //Ignore 0 (default) values from server side @@ -903,6 +908,10 @@ $(document).ready(function () { } }); + let primary_vaccine = url.searchParams.has('vaccine_type') ? url.searchParams.get('vaccine_type') : null; + let booster_vaccine = url.searchParams.has('vaccine_booster_type') ? url.searchParams.get('vaccine_booster_type') : null; + $(`#vaccine_booster_type > option[data-primary-vaccine="${primary_vaccine}"][value="${booster_vaccine}"]`).attr('selected', true); + // Handle default URL values if they are not explicitly defined. if (Array.from(url.searchParams).length > 0) { if (!url.searchParams.has('location_name')) { diff --git a/caimira/apps/templates/base/calculator.form.html.j2 b/caimira/apps/templates/base/calculator.form.html.j2 index 1723e7d8..215eef2d 100644 --- a/caimira/apps/templates/base/calculator.form.html.j2 +++ b/caimira/apps/templates/base/calculator.form.html.j2 @@ -408,8 +408,8 @@