Skip to content
New issue

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

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

Already on GitHub? # to your account

[LINST/Instruments] Backporting fixes from 24 + group errors #8091

Merged
merged 2 commits into from
Jun 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions php/libraries/NDB_BVL_Instrument_LINST.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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";
}
Expand Down Expand Up @@ -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'])) {
Expand All @@ -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();
}
Expand Down Expand Up @@ -579,6 +594,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(
Expand Down Expand Up @@ -632,7 +649,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) {
Expand Down Expand Up @@ -683,7 +699,7 @@ class NDB_BVL_Instrument_LINST extends \NDB_BVL_Instrument
$pieces[1],
$pieces[2],
$opt,
"multiple"
[ "multiple" => "multiple" ]
);
} else {
$Group['Elements'][]
Expand Down Expand Up @@ -729,7 +745,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',
Expand Down