growthcharts / james

Joint Automatic Measurement and Evaluation System (JAMES)
https://growthcharts.org/james/
GNU Affero General Public License v3.0
3 stars 0 forks source link

Incorrect initialisation of user interface when child is older than 4 years #29

Closed stefvanbuuren closed 7 months ago

stefvanbuuren commented 7 months ago

In JAMES 1.5.9, the following request does not correctly initialize the UI and deactivate the radiobuttons. It happens for all children with a measurement > 4 years.

# "Initialization >4Y" bug in JAMES 1.5.9
library(jamesclient)
library(httr)
library(jsonlite)

host <- "https://james.groeidiagrammen.nl"
fn <- system.file("extdata", "bds_v3.0", "terneuzen", "T_1017.json",
                  package = "jamesdemodata", mustWork = TRUE)
r <- james_post(host = host, path = "/blend/request/json", sitehost = host, txt = fn)
browseURL(r$parsed$site)

Created on 2024-04-12 with reprex v2.1.0

stefvanbuuren commented 7 months ago

Possibly related to #6

stefvanbuuren commented 7 months ago

Problem identified. In start.js line 166, we have

      if (output.agegrp !== "1-21y") {
        document.forms.agegrp_dsc[output.agegrp].checked = true;
      }

The test always evaluated to true because output.agegrp is an array, and the next line then errors.

Repair by comparing to the first element

    if (output.agegrp[0] !== "1-21y") {
        document.forms.agegrp_dsc[output.agegrp[0]].checked = true;
      }

Note: This change should be done everywhere where output.{xxx} is compared using the strict !== operator.

stefvanbuuren commented 7 months ago

The following now runs:

# "Initialization >4Y" bug in JAMES 1.5.9
# Solved in JAMES 1.5.10 (12 April 2024)
library(jamesclient)
library(httr)
library(jsonlite)

host <- "https://james.groeidiagrammen.nl"
fn <- system.file("extdata", "bds_v3.0", "terneuzen", "T_1017.json",
                  package = "jamesdemodata", mustWork = TRUE)
r <- james_post(host = host, path = "/blend/request/json", sitehost = host, txt = fn)
browseURL(r$parsed$site)