From d68877bf882fbc4f649f2c9f00335b9b90c14d6f Mon Sep 17 00:00:00 2001 From: ridz1208 Date: Thu, 12 May 2022 10:39:08 -0400 Subject: [PATCH 1/2] [LINST/Instruments] Backporting fixes from 24 --- php/libraries/NDB_BVL_Instrument_LINST.class.inc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/php/libraries/NDB_BVL_Instrument_LINST.class.inc b/php/libraries/NDB_BVL_Instrument_LINST.class.inc index 6d84f5876f9..f4fbd4fef55 100644 --- a/php/libraries/NDB_BVL_Instrument_LINST.class.inc +++ b/php/libraries/NDB_BVL_Instrument_LINST.class.inc @@ -579,6 +579,8 @@ class NDB_BVL_Instrument_LINST extends \NDB_BVL_Instrument // Set date format $dateFormat = isset($pieces[5]) ? trim($pieces[5]) : ""; + $this->LinstQuestions[$pieces[1]] = array('type' => 'date'); + if ($dateFormat === 'MonthYear') { // Shows date without day of month $this->addMonthYear( @@ -632,7 +634,6 @@ class NDB_BVL_Instrument_LINST extends \NDB_BVL_Instrument $this->_requiredElements[] = $fieldname; $firstFieldOfPage = false; } - $this->LinstQuestions[$pieces[1]] = array('type' => 'date'); break; case 'numeric': if ($addElements) { @@ -683,7 +684,7 @@ class NDB_BVL_Instrument_LINST extends \NDB_BVL_Instrument $pieces[1], $pieces[2], $opt, - "multiple" + [ "multiple" => "multiple" ] ); } else { $Group['Elements'][] @@ -729,7 +730,6 @@ class NDB_BVL_Instrument_LINST extends \NDB_BVL_Instrument $this->_doubleDataEntryDiffIgnoreColumns[] = $pieces[1]; if ($addElements) { if ($Group['Name'] != null) { - print "Creating $pieces[1] with label: $pieces[2]"; $Group['Elements'][] = $this->form->createElement( 'static', From 300f2e616360e9f1dddb6df03befafec0eefd2e2 Mon Sep 17 00:00:00 2001 From: ridz1208 Date: Mon, 16 May 2022 15:55:42 -0400 Subject: [PATCH 2/2] group rules --- .../NDB_BVL_Instrument_LINST.class.inc | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/php/libraries/NDB_BVL_Instrument_LINST.class.inc b/php/libraries/NDB_BVL_Instrument_LINST.class.inc index f4fbd4fef55..5012cf344cd 100644 --- a/php/libraries/NDB_BVL_Instrument_LINST.class.inc +++ b/php/libraries/NDB_BVL_Instrument_LINST.class.inc @@ -36,6 +36,9 @@ class NDB_BVL_Instrument_LINST extends \NDB_BVL_Instrument public $LinstLines = array(); + // array of the format "field_name" => "group_name" + protected $GroupElements = []; + /** * Sets up the variables required for a LINST instrument to load * @@ -263,7 +266,11 @@ class NDB_BVL_Instrument_LINST extends \NDB_BVL_Instrument } else if (substr($elname, -7) != "_status" && !in_array($elname, array("page", "subtest")) ) { - $errors[$elname] = "Required."; + // Check if element part of a group. + // If so, the error should be on the group to show up + $errorEl = $this->GroupElements[$elname] ?? $elname; + $errors[$errorEl] = "$elname is required."; + if ($this->XINDebug) { echo "Required by default"; } @@ -481,7 +488,7 @@ class NDB_BVL_Instrument_LINST extends \NDB_BVL_Instrument break; case 'begingroup': if ($addElements) { - $Group['Name'] = $pieces[1] . '_group'; + $Group['Name'] = trim($pieces[1]) . '_group'; $Group['Delimiter'] = trim($pieces[2]); if (empty($Group['Delimiter'])) { @@ -500,6 +507,14 @@ class NDB_BVL_Instrument_LINST extends \NDB_BVL_Instrument false ); + // Track elements and their groups for XIN errors proper + // higlighting in the browser + foreach ($Group['Elements'] as $el) { + if (isset($el['name'])) { + $this->GroupElements[$el['name']] = $Group['Name']; + } + } + $Group['Name'] = null; $Group['Elements'] = array(); }