Skip to content

Commit b0ff235

Browse files
committed
fix error with unit fields
1 parent 7a2bb17 commit b0ff235

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

renderer.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -365,16 +365,16 @@ protected function create_input_box(qtype_formulas_part $part, $answerindex,
365365
/** @var qype_formulas_question $question */
366366
$question = $qa->get_question();
367367

368-
$variablename = $part->partindex;
369-
if ($part->has_combined_unit_field()) {
370-
$variablename .= '_';
368+
// The variable name will be N_M for answer #M in part #N or N_ for the (single) combined
369+
// unit field of part N, or N_u for the (single) unit field of part N.
370+
// FIXME: N_xxx for unit field with xxx = numbox
371+
$variablename = $part->partindex . '_';
372+
if ($answerindex === self::UNIT_FIELD) {
373+
$variablename .= $part->numbox;
371374
} else {
372-
$variablename .= ($answerindex == $part->numbox ? '_u' : "_{$answerindex}");
375+
$variablename .= ($answerindex === self::COMBINED_FIELD ? '' : $answerindex);
373376
}
374377

375-
// The variable name will be N_M for answer #M in part #N or N_ for the (single) combined
376-
// unit field of part N, or N_u for the (single) unit field of part N.
377-
$variablename = "{$part->partindex}_{$answerindex}";
378378
$currentanswer = $qa->get_last_qt_var($variablename);
379379
$inputname = $qa->get_qt_field_name($variablename);
380380

@@ -392,9 +392,12 @@ protected function create_input_box(qtype_formulas_part $part, $answerindex,
392392
default:
393393
$titlestring = 'number';
394394
}
395-
if ($part->postunit !== '') {
395+
if ($answerindex === self::COMBINED_FIELD) {
396396
$titlestring .= '_unit';
397397
}
398+
if ($answerindex === self::UNIT_FIELD) {
399+
$titlestring = 'unit';
400+
}
398401
$title = get_string($titlestring, 'qtype_formulas');
399402

400403
$inputattributes = [

0 commit comments

Comments
 (0)