From d95c82ab59680c53db1aadc40d5b83a94baadd96 Mon Sep 17 00:00:00 2001 From: tjhunt Date: Mon, 2 Apr 2007 13:02:09 +0000 Subject: [PATCH] MDL-9173 - Can't create match anything answer to numerical question type. Merged from OU Moodle. --- lang/en_utf8/qtype_numerical.php | 1 + question/type/numerical/edit_numerical_form.php | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lang/en_utf8/qtype_numerical.php b/lang/en_utf8/qtype_numerical.php index 9239f86bf1..1aa6af279b 100644 --- a/lang/en_utf8/qtype_numerical.php +++ b/lang/en_utf8/qtype_numerical.php @@ -2,6 +2,7 @@ $string['addmoreanswerblanks'] = 'Blanks for {no} More Answers'; $string['addmoreunitblanks'] = 'Blanks for {no} More Units'; $string['answerno'] = 'Answer $a'; +$string['answermustbenumberorstar'] = 'The answer must be a number, or \'*\'.'; $string['errorrepeatedunit'] = 'You cannot have two units with the same name.'; $string['errornomultiplier'] = 'You must specify a multiplier for this unit.'; $string['notenoughanswers'] = 'You must enter at least one answer.'; diff --git a/question/type/numerical/edit_numerical_form.php b/question/type/numerical/edit_numerical_form.php index ac534a8493..61d8d89f9e 100644 --- a/question/type/numerical/edit_numerical_form.php +++ b/question/type/numerical/edit_numerical_form.php @@ -28,7 +28,7 @@ class question_edit_numerical_form extends question_edit_form { $repeated[] =& $mform->createElement('header', 'answerhdr', get_string('answerno', 'qtype_numerical', '{no}')); $repeated[] =& $mform->createElement('text', 'answer', get_string('answer', 'quiz')); - $mform->setType('answer', PARAM_NUMBER); + $mform->setType('answer', PARAM_RAW); $repeated[] =& $mform->createElement('text', 'tolerance', get_string('acceptederror', 'quiz')); $mform->setType('tolerance', PARAM_NUMBER); @@ -120,8 +120,11 @@ class question_edit_numerical_form extends question_edit_form { $answers = $data['answer']; foreach ($answers as $key => $answer) { $trimmedanswer = trim($answer); - if ($trimmedanswer!=''){ + if ($trimmedanswer != '') { $answercount++; + if (!(is_numeric($trimmedanswer) || $trimmedanswer == '*')) { + $errors["answer[$key]"] = get_string('answermustbenumberorstar', 'qtype_numerical'); + } if ($data['fraction'][$key] == 1) { $maxgrade = true; } -- 2.39.5