Moodle
  1. Moodle
  2. MDL-38355

Answer input field in cloze question too long

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.3.3, 2.4.1, 2.5
    • Fix Version/s: 2.3.7, 2.4.4
    • Component/s: Questions
    • Labels:
      None
    • Testing Instructions:
      Hide

      1. Create the suggested multianswer question:

      1. Маша {1:SA:=ест} (есть) яйцо и {1:SA:=говорит} (говорить): − Я {1:SA:=хочу} (хотеть) пить сок. Или молоко.
      

      2. Preview it.

      3. Click the 'Fill in correct responses' button.

      4. Verify that the input boxes are just a little bit larger than required to display the right answers.

      Show
      1. Create the suggested multianswer question: 1. Маша {1:SA:=ест} (есть) яйцо и {1:SA:=говорит} (говорить): − Я {1:SA:=хочу} (хотеть) пить сок. Или молоко. 2. Preview it. 3. Click the 'Fill in correct responses' button. 4. Verify that the input boxes are just a little bit larger than required to display the right answers.
    • Affected Branches:
      MOODLE_23_STABLE, MOODLE_24_STABLE, MOODLE_25_STABLE
    • Fixed Branches:
      MOODLE_23_STABLE, MOODLE_24_STABLE
    • Pull from Repository:
    • Pull 2.4 Branch:
    • Pull Master Branch:
    • Rank:
      48242

      Description

      When using different languages (Russian, Greek etc.) in cloze questions answer field is usually longer than the actual answer is.

      How to reproduce:
      1. Create a cloze question with following content

                  1. Маша {1:SA:=ест} (есть) яйцо и {1:SA:=говорит} (говорить):
                     − Я {1:SA:=хочу} (хотеть) пить сок. Или молоко. 

      2. Open preview of the question and fill in the answers (input fields are almost double the size of the answer)

      Since all pages are UTF-8 enconding, fixing this looked simple. In 2.4.1 applied the same solution as in 2.3.3 - replace strlen with mb_strlen

      For 2.4.1 the affected file is question/type/multianswer/rendere.php at line 192 here with two occurrences of strlen commented and replaced:

      // $size = max(1, strlen(trim($response)) + 1);
      $size = max(1, textlib::strlen(trim($response)) + 1);
      foreach ($subq->answers as $ans) {
      // $size = max($size, strlen(trim($ans->answer)));
      $size = max($size, textlib::strlen(trim($ans->answer)));
      

      For 2.3.3 question/type/multianswer/questiontype.php strlen replaced with mb_strlen:

      foreach ($answers as $answer) {
      if (mb_strlen(trim($answer->answer),"UTF-8") > $size ){
      $size = mb_strlen(trim($answer->answer), "UTF-8");
      }
      }
      if (mb_strlen(trim($response),"UTF-8")> $size ){
      $size = mb_strlen(trim($response),"UTF-8")+1;
      }
      $size = $size + rand(0,$size*0.15);
      
      $size > 60 ? $size = 60 : $size = $size;
                          $styleinfo = "size=\"$size\"";
      

        Activity

        Hide
        Jean-Michel Vedrine added a comment -

        Hello Duan,
        You should use textlib::strlen rather than mb_strlen so that your code is compatible with all Moodle installs.

        Show
        Jean-Michel Vedrine added a comment - Hello Duan, You should use textlib::strlen rather than mb_strlen so that your code is compatible with all Moodle installs.
        Hide
        Dušan Ristić added a comment - - edited

        Hi Jean-Michel,
        I've changed mb_strlen to textlib::strlen as suggested and it works, thanks for suggesting the right method.

        Show
        Dušan Ristić added a comment - - edited Hi Jean-Michel, I've changed mb_strlen to textlib::strlen as suggested and it works, thanks for suggesting the right method.
        Hide
        Jean-Michel Vedrine added a comment - - edited

        Hello Duan,
        Thanks, but just a small typo:
        It's textlib::strlen, not text::strlen
        Because the strlen function is in the Moodle textlib library. And as it's a static function you are calling it with the double colon :: syntax.

        Show
        Jean-Michel Vedrine added a comment - - edited Hello Duan, Thanks, but just a small typo: It's textlib::strlen, not text::strlen Because the strlen function is in the Moodle textlib library. And as it's a static function you are calling it with the double colon :: syntax.
        Hide
        Dušan Ristić added a comment -

        Hi Jean-Micheal,
        Sorry for typo, I was working couple of things at the same time and didn't noticed all the mistakes I've created editing post.
        I think it's ok now.
        As for 2.3.3 version it's not working with textlib::strlen, but I'll try to check it latter when I get some free time.

        Show
        Dušan Ristić added a comment - Hi Jean-Micheal, Sorry for typo, I was working couple of things at the same time and didn't noticed all the mistakes I've created editing post. I think it's ok now. As for 2.3.3 version it's not working with textlib::strlen, but I'll try to check it latter when I get some free time.
        Hide
        Tim Hunt added a comment -

        Thanks Dušan Ristić for this bug report, and you suggested fix. I have made it into a git commit and submitted it for integration, so hopefully it will become part of Moodle next week.

        Show
        Tim Hunt added a comment - Thanks Dušan Ristić for this bug report, and you suggested fix. I have made it into a git commit and submitted it for integration, so hopefully it will become part of Moodle next week.
        Hide
        Eloy Lafuente (stronk7) added a comment -

        Integrated (23, 24 & master), thanks!

        Show
        Eloy Lafuente (stronk7) added a comment - Integrated (23, 24 & master), thanks!
        Hide
        Rajesh Taneja added a comment -

        Thanks Dušan, Jean-Michel and Tim.

        Input boxes are just a little bit larger than the correct answers.

        Show
        Rajesh Taneja added a comment - Thanks Dušan, Jean-Michel and Tim. Input boxes are just a little bit larger than the correct answers.
        Hide
        Damyon Wiese added a comment -

        This issue has been integrated upstream and is now available via git (and in some hours, via mirrors and downloads).

        Thanks for your contributions!

        Show
        Damyon Wiese added a comment - This issue has been integrated upstream and is now available via git (and in some hours, via mirrors and downloads). Thanks for your contributions!

          People

          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: