Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-3274

Adaptive text field length in cloze test

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Trivial
    • Resolution: Fixed
    • Affects Version/s: 1.5
    • Fix Version/s: 1.9
    • Component/s: Quiz
    • Labels:
      None
    • Environment:
      All
    • Affected Branches:
      MOODLE_15_STABLE
    • Fixed Branches:
      MOODLE_19_STABLE

      Description

      At request of one of our teachers using cloze tests extensively I have modified the code for multianswer question so that the size of a text field corresponds to the longest of the right answers to that particular (short answer) question.

      Motivation: Sometimes the default text fields' size=12 is too small and the students cannot see their whole answer in the field; on the other hand, longer fields are not necessary in other cases - therefore the adaptive length.

      Modified file: http://moodle.cvs.sourceforge.net/moodle/moodle/mod/quiz/questiontypes/multianswer/questiontype.php (around line 265)

      Modification:

      //echo <input $style $readonly $popup name=\$inputname\ // Moodle original lines

      // type=\text\ value=\$response\ size=\12\ /> ; // Moodle original lines

      // ELF - input field as long as the longest short answer

      $xq = explode (question,$inputname);

      $xquestid = explode (multianswer,$xq[1]); // $xquestid[1] contains the id of the actual part of the multianswer question

      if ($xshortanswers = get_record(quiz_multianswers,id,$xquestid[1],question,$question->id,answertype,1)) {

      $xshortanswersids = explode (,,$xshortanswers->answers);

      $size = 0; // to have the variable defined

      foreach ($xshortanswersids as $kk => $xshrtanswrid) {

      if ($xanswer = get_record(quiz_answers,id,$xshrtanswrid,fraction,1))

      { $xsize = strlen(trim($xanswer->answer)); // get the length of this answer with fraction 1 $xsize > $size ? $size = $xsize : $size = $size; }

      }

      $size > 60 ? $size = 60 : $size = $size;

      unset($xshortanswersids);

      }

      if ($xsize)

      { echo <input $style $readonly $popup name=\$inputname\ type=\text\ value=\$response\ size=\$size\ /> ; unset ($xsize); }

      else

      { echo <input $style $readonly $popup name=\$inputname\ type=\text\ value=\$response\ size=\12\ /> ; }

      // End ELF modification

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Votes:
                  1 Vote for this issue
                  Watchers:
                  5 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Fix Release Date:
                    3/Mar/08