Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion doc/en/Authoring/Inputs/Matrix_input.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ The matrix of variable size input is a textarea into which students type in thei

Students must separate their matrix elements by spaces, and newline characters.

Input box size is used to determine the starting width of the input.
Input box size is used to determine the starting width of the input.

If you use the `allowempty` option then an empty answer is indicated by the `EMPTYANSWER` tag. This is a different _type_ than a matrix. (We could have chosen `matrix()` as the empty matrix, but `EMPTYANSWER` is more in keeping with other inputs.)
9 changes: 4 additions & 5 deletions stack/input/varmatrix/varmatrix.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ protected function response_to_contents($response) {
$contents = [];
if (array_key_exists($this->name, $response)) {
$sans = $response[$this->name];
if (trim($sans) === '' && $this->get_extra_option('allowempty')) {
return(['EMPTYANSWER']);
}
$rowsin = explode("\n", $sans);
foreach ($rowsin as $key => $row) {
$cleanrow = trim($row);
Expand All @@ -200,7 +203,6 @@ protected function response_to_contents($response) {
$maxlen = max(count($entries), $maxlen);
$contents[$key] = $entries;
}

foreach ($contents as $key => $row) {
// Pad out short rows.
$padrow = [];
Expand All @@ -209,9 +211,6 @@ protected function response_to_contents($response) {
}
$contents[$key] = array_merge($row, $padrow);
}
if ($contents == [] && $this->get_extra_option('allowempty')) {
$contents = ['EMPTYANSWER'];
}
return $contents;
}

Expand Down Expand Up @@ -241,7 +240,7 @@ protected function caslines_to_answer($caslines, $secrules = false) {
*/
public function contents_to_maxima($contents) {
if ($contents == ['EMPTYANSWER']) {
return 'matrix(EMPTYCHAR)';
return 'EMPTYANSWER';
}
$matrix = [];
foreach ($contents as $row) {
Expand Down
2 changes: 1 addition & 1 deletion tests/input_varmatrix_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public function test_validate_student_response_blank_allowempty(): void {
);
$this->assertEquals(stack_input::SCORE, $state->status);
$this->assertEquals('', $state->note);
$this->assertEquals('matrix(EMPTYCHAR)', $state->contentsmodified);
$this->assertEquals('EMPTYANSWER', $state->contentsmodified);
$this->assertEquals(
'',
$state->contentsdisplayed
Expand Down
Loading