Change size of short answer text entry box?

Change size of short answer text entry box?

by James Phillips -
Number of replies: 21
Dear All,

I was wondering if it were possible to change the size of the text entry box for short answer questions in a quiz? I managed to achieve this (with a great deal of help!) for the short answer in the lesson but things seem a little different with the quiz module. Any help would be much appreciated.

Best regards,

James Phillips
Average of ratings: -
In reply to James Phillips

Re: Change size of short answer text entry box?

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Hi James,

  1. Which Moodle version are you using?
  2. Where would you like to change the size of the input box for short answer questions in the quiz?
    1. In teacher edit mode (it is now approx. 20 chars long)
    2. or in student answer mode (it is not approx. 60 chars long)
    3. or both? What lengths would you like?

Joseph


In reply to Joseph Rézeau

Re: Change size of short answer text entry box?

by James Phillips -
Hi Joseph!
Sorry for troubling you yet again!
A two line box 60 characters long in student answer mode and teacher edit mode would be great! I am using moodle 1.8.2 and intend to not upgrade for as long as humanly possible.

Best regards,

James Phillips
In reply to James Phillips

Re: Change size of short answer text entry box?

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Hi James,

Because of the different answer analysis system for the short answer question in the Lesson and in the Quiz modules, it is not possible to provide for a 2-line answer box. You can only customize the length of the answer box by doing the following. For Moodle 1.8.2.

Go to file edit_shortanswer_form.php. About line 31 replace:

$repeated[] =& $mform->createElement('text', 'answer', get_string('answer', 'quiz'));

with

$repeated[] =& $mform->createElement('text', 'answer', get_string('answer', 'quiz'),array('size'=>67));

This will give you a box for approx. 60 characters (this may vary a little according to your current theme and current browser text size, etc.)

By default, i.e. if no value is given, that input box is 20 characters long. I also find it ridiculously short.

Curiously, In student answer mode, the input box provided is already set to size = 80.

Tim, if you're listening, why not make things more consistent and have the answer inputbox in teacher edit mode 80 characters long too? I thought I'd asked for this some time ago already.

Hope that helps,

Joseph

Attachment image00.jpg
In reply to Joseph Rézeau

Re: Change size of short answer text entry box?

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
It depends how busy I am when you ask whether I pick up minor things from the forum. Or how quickly things in the tracker get dealt with. At least if they are in the tracker, they don't get forgotten about if I am too bust at the time. (hint)



In reply to Joseph Rézeau

Re: Change size of short answer text entry box?

by Bernd Greifluss -
Hi Joseph,

that is very unfortunate. I would need a multiple line short-answer textbox as well. Is there still no solution to this? Where and how is the input type for short-answer questions set?

I am using Version 1.9.3.

Thanks for any hints...

Cheers
Bernd
In reply to Bernd Greifluss

Re: Change size of short answer text entry box?

by Jeff Forssell -
Exactly why do you need a two line answer? Can you give an example question with answer?

It's often possible to rethink a question if one knows what it is about.

BTW the tracker issue is already marked resolved! (So I was too late to vote! Isn't this some kind of fast resolution record. Certainly a sterling example!)
In reply to Jeff Forssell

Re: Change size of short answer text entry box?

by Bernd Greifluss -

Hi Jeff,

there are two aspects:

Layout:
Thematically, our questions of interest are in fact essay questions, i.e. students should write up to 500 characters usually. Therefore a single line input field is a bit small. But, on the other hand, the standard textbox of the essay question is simply to large. Fewer lines and a smaller width would be great.

Autocorrection:
We would like to use the autocorrection functionality of the short answer questions. Namely, grading an answer by letting moodle scan the answer automatically for certain keywords (separated by wildcards, or, ideally by matching regular expressions, but that's another question...). This is not possible with the essay textbox question type.

Thanks a lot for any advice. I am also willing to change some code (I am pretty good with php) but I need some guidance were to start.

Bernd

In reply to Bernd Greifluss

Re: Change size of short answer text entry box?

by Pierre Pichet -
Using Joseph Rézeau regexp type could be the solution.
It will be easy to set the text size whitout any side effects to other question types like numerical.

Pierre
In reply to Bernd Greifluss

Re: Change size of short answer text entry box?

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Bernd,
In spite of Pierre Pichet's suggestion to use my REGEXP question type, I'm afraid that what you want to achieve is not realistic. The REGEXP question type does use regular expressions to scan SHORT students responses for a) the presence of correct words or groups of words and b) the absence of obligatory words. It will certainly not work on text chunks of 500 words!
You can try it out, but don't set your expectations too high.
Joseph
In reply to Bernd Greifluss

Re: Change size of short answer text entry box?

by Jeff Forssell -
Even though the "father of regular expressions question type", JR , is pessimistic, i think this is a very interesting way of using it. Even if it can't give any exact "marking" it should be able to give some encouragement if important terms are there (and corrective guidance if they are missing). I'd like to be able to even "push the envelope" to much more than 500 chars. If your interface can let the teacher choose height and width of the input box that would be great!

There are some features (like showing the teacher which possible answers a certain expression could give) that probably have to be turned off. Regular expressions is a wonderful tool for teachers that want to give feedback.

Do keep us posted on how it goes! (I'M HOPING approve )

In reply to Jeff Forssell

Re: Change size of short answer text entry box?

by Bernd Greifluss -
Thank you all very much for your feedback.

However, I am still not satisfied (sorry!!!):

@Joseph:
Unfortunately, I can't get the regex question type to work. Whenever I am trying to save the question, I get an "Error: Missing question options! Could not insert quiz regexp options!". I am using Moodle version 1.9.3 (Build: 20081015). All I did, was downloading the regexp questiontype from moodle.org/mod/data/view.php?d=13&rid=338 ("for Moodle 1.9") and extract it to <root>\question\type. I also went to the Frontpage, logged in as admin, as proposed at http://moodle.org/mod/forum/discuss.php?d=38542#p367897 What have I done wrong?
I also tried using the "latest version" of the regexp question type, but then, all I get after saving, is a blank white page.

@Pierre:
What do you mean by "It will be easy to set the text size...". First of all, where do I do this and secondly, that doesn't solve my problem, does it? Altering the text size, will not result in a two- or multiple-lines textbox!? It will still be a single line input field with small letters.

Thanks a lot for any further advice!
Bernd

In reply to Bernd Greifluss

Re: Change size of short answer text entry box?

by Frank Ralf -

Hi Bernd,

the following is just a hint, not yet a solution.

Changing the text input tag in moodle\question\type\shortanswer\display.html from

<div class="answer">
  <input type="text" class="<?php echo $class; ?>" 
  <?php echo "$readonly $inputname $value"; ?> size="80"/>
  <?php echo $feedbackimg; ?>
</div>

to a textarea tag like so:

<div class="answer">
  <textarea rows= "3" cols ="80" class="<?php echo $class; ?>" >
  <?php echo "$readonly $inputname $value"; ?>
  </textarea>
  <?php echo $feedbackimg; ?>
</div>

will give you the larger entry field. But I suppose it breaks the code for calling the answer from the database because of the changed tags.

hth Frank

In reply to Frank Ralf

Re: Change size of short answer text entry box?

by Bernd Greifluss -
Thanks a lot Frank,

I've just found out as well. Display.html was exactly what I was looking for. So far, it seems to work perfectly: However, as you said, you have to split up the parameters readonly, inputname and value appropriately. I.e. replace line 15 in \question\type\shortanswer\display.html

<input type="text" class="<?php echo $class; ?>" <?php echo "$readonly $inputname $value"; ?> size="80"/>


with:

<textarea <?php echo "$readonly $inputname"; ?> class="<?php echo $class; ?>" cols="50" rows="5">
<?php echo substr($value, 8, (strlen($value)-10)); ?>
</textarea>


Thanks again to everyone!
In reply to Bernd Greifluss

Re: Change size of short answer text entry box?

by christ fernando -

C:\XAMPPlite\server\moodle\question\type\shortanswer\display.html

I open the display.html file and replace the code like what u did and save the file, but i am unable to get it even when i refresh the moodle page or restarting the whole moodle server.

In reply to Frank Ralf

Mistake in above HTML

by Frank Ralf -

Oops, there is a mistake in the textarea HTML. One angel bracket is misplaced. The code should look like this.

<div class="answer">
  <textarea rows= "3" cols ="80" class="<?php echo $class; ?>" 
  <?php echo "$readonly $inputname $value"; ?> >
  </textarea>
  <?php echo $feedbackimg; ?>
</div>

That seems to do the trick with my development installation but I only did some quick testing.

Kind regards, Frank

Average of ratings: Useful (1)
In reply to Frank Ralf

Short answer text area

by N Hansen -
Frank-That does the trick, but there is something strange going on. I had a similar hack in 1.6.5 with a textarea of 1 row with 30 columns, and I made it the same in 1.8.10, but it is 2 rows and maybe 40 columns when it is displayed with a very short scroll bar on the side (so small you can't scroll it). I'm not sure what to make of that.
In reply to Frank Ralf

Re: Mistake in above HTML

by N Hansen -
I've done some more testing of this and have encountered a problem. When a student is reviewing the quiz, the textarea is displayed as a grey box and their answer is actually not displayed although looking at the code for the page it is there, e.g..

 <textarea rows="1" cols="30" class="glyph" readonly="readonly" name="resp402_" value="sḫtἰw">
 </textarea>

Oddly enough, I used similar code in 1.6.5 and did not have this problem. Anyone know a solution for it

My reason for using the textarea at all was because students need to enter letters with diacritics on the bottom and the regular input field on a Mac was cutting those diacritics. I wonder if there is any other workaround for this instead of the textarea one.
In reply to N Hansen

Re: Mistake in above HTML

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
With <textarea> you don't put the value inside a value="" attribute. You should put it inside the tag, so

<textarea rows="1" cols="30" class="glyph" readonly="readonly" name="resp402_">
sḫtἰw
</textarea>

Average of ratings: Useful (1)
In reply to Bernd Greifluss

Re: Change size of short answer text entry box?

by Oleg Sychev -
Picture of Core developers Picture of Plugin developers
Bernd you could try to use my preg question type (search Modules and Plugins database). You still need to edit display.html and overload print_question_formulation_and_controls function with it copy from shortanswer to use display.html from preg folder.

Preg question type support any regular expressions that PHP preg_match function could handle. That is much more that regex question type allows.
In reply to Joseph Rézeau

Re: Change size of short answer text entry box?

by Abbas Shaikh -

Hi

Can anyone also help on muliple choice answer field. I have some script codes as answers, so want to modify the answer field as multi line text area.

Thanks,

 Abbas