]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-9173 - Can't create match anything answer to numerical question type. Merged...
authortjhunt <tjhunt>
Mon, 2 Apr 2007 13:02:09 +0000 (13:02 +0000)
committertjhunt <tjhunt>
Mon, 2 Apr 2007 13:02:09 +0000 (13:02 +0000)
lang/en_utf8/qtype_numerical.php
question/type/numerical/edit_numerical_form.php

index 9239f86bf153c4108dfe0f8300b78dcbc55c0847..1aa6af279b52bee30890993f4cc83b518d4c5f02 100644 (file)
@@ -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.';
index ac534a8493c8d0c1a0f9752b84d22aee3e9b4ef2..61d8d89f9ecdea680aba38f898d670d39162f9a2 100644 (file)
@@ -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;
                 }