public function get_per_answer_fields($mform, $label, $gradeoptions,
            &$repeatedoptions, &$answersoption) {
        $repeated = parent::get_per_answer_fields($mform, $label, $gradeoptions,
                $repeatedoptions, $answersoption);

        // 1 is the answer. 3 is tolerance.
        $repeated[1]->setLabel(get_string('correctanswerformula', 'qtype_calculated') . '=');
        $repeated[1]->setSize(55);
        $repeated[3]->setLabel(get_string('tolerance', 'qtype_calculated') . '=');
        $repeatedoptions['tolerance']['default'] = 0.01;

        $addrepeated = array();
        $addrepeated[] = $mform->createElement('select', 'tolerancetype',
                get_string('tolerancetype', 'qtype_numerical'), $this->qtypeobj->tolerance_types());

        $addrepeated[] = $mform->createElement('select', 'correctanswerlength',
                get_string('correctanswershows', 'qtype_calculated'), range(0, 9));
        $repeatedoptions['correctanswerlength']['default'] = 2;

        $answerlengthformats = array(
            '1' => get_string('decimalformat', 'qtype_numerical'),
            '2' => get_string('significantfiguresformat', 'qtype_calculated')
        );
        $addrepeated[] = $mform->createElement('select', 'correctanswerformat',
                get_string('correctanswershowsformat', 'qtype_calculated'), $answerlengthformats);

        array_splice($repeated, 4, 0, $addrepeated);

        return $repeated;
    }
 public function get_per_answer_fields($mform, $label, $gradeoptions, &$repeatedoptions, &$answersoption)
 {
     $repeated = parent::get_per_answer_fields($mform, $label, $gradeoptions, $repeatedoptions, $answersoption);
     // Reorganise answer options group. 0 is the answer. 1 is tolerance. 2 is Grade.
     $answeroptions = $repeated[0]->getElements();
     // Tolerance field will be part of its own group.
     $tolerance = $answeroptions[1];
     // Update Answer options group to contain only answer and grade fields.
     $answeroptions[0]->setSize(55);
     $answeroptions = array($answeroptions[0], $answeroptions[2]);
     $repeated[0]->setElements($answeroptions);
     // Update answer field and group label.
     $repeated[0]->setLabel(get_string('answerformula', 'qtype_calculated', '{no}') . ' =');
     $answeroptions[0]->setLabel(get_string('answerformula', 'qtype_calculated', '{no}') . ' =');
     // Get feedback field to re append later.
     $feedback = array_pop($repeated);
     // Create tolerance group.
     $answertolerance = array();
     $tolerance->setLabel(get_string('tolerance', 'qtype_calculated') . '=');
     $answertolerance[] = $tolerance;
     $answertolerance[] = $mform->createElement('select', 'tolerancetype', get_string('tolerancetype', 'qtype_calculated'), $this->qtypeobj->tolerance_types());
     $repeated[] = $mform->createElement('group', 'answertolerance', get_string('tolerance', 'qtype_calculated'), $answertolerance, null, false);
     $repeatedoptions['tolerance']['default'] = 0.01;
     // Create display group.
     $answerdisplay = array();
     $answerdisplay[] = $mform->createElement('select', 'correctanswerlength', get_string('answerdisplay', 'qtype_calculated'), range(0, 9));
     $repeatedoptions['correctanswerlength']['default'] = 2;
     $answerlengthformats = array('1' => get_string('decimalformat', 'qtype_numerical'), '2' => get_string('significantfiguresformat', 'qtype_calculated'));
     $answerdisplay[] = $mform->createElement('select', 'correctanswerformat', get_string('correctanswershowsformat', 'qtype_calculated'), $answerlengthformats);
     $repeated[] = $mform->createElement('group', 'answerdisplay', get_string('answerdisplay', 'qtype_calculated'), $answerdisplay, null, false);
     // Add feedback.
     $repeated[] = $feedback;
     return $repeated;
 }