How to set the size of HTML input element

How to set the size of HTML input element

by Pierre Pichet -
Number of replies: 3
Correcting the cloze question display, I need to set the input answer field to the answer length.
See MDL-3274
Using simple size =\"".$size."\" where $size can vary from 1 to the response size works correctly on Mac Safari but on other like Windows Explorer or Firefox give a larger size than necessary when $size is less than 4.
Using em width parameter works well for Explorer but not Safari.

Pierre

P.S. Forum search does not seem to work correctly as we cannot specify in which forum we want the search, so I post my simple question directly here.
Average of ratings: -
In reply to Pierre Pichet

Re: How to set the size of HTML input element

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
I have never really understood how browsers turn the size="" attribute into an actual size. As long as there is enough space, I would not worry if it was slightly too big.

P.S. Forum search: You have go to advanced search to specify a forum.
In reply to Tim Hunt

Re: How to set the size of HTML input element

by Pierre Pichet -
The default minimum size seems to be 4 characters for IE and FF.
A moodle advanced or a google search does not give more info.
So for MDL-3274 I will use the normal size parameter and let Moodle local administrator modify locally with the style width parameter if there is a need.

Pierre

P.S. Last night the advanced search did not display the forum selection button in IE or FF. Today this is OK...

In reply to Pierre Pichet

Re: How to set the size of HTML input element

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

Hi Pierre and Tim,

I was not aware of MDL-3274 which is an old bug recently revived. Further to this discussion (which did not spark a lot of reactions at the timewink) I have added the following to my local version of multianswer/questiontype.php and am quite happy with it. I see no reason to add a random length element as suggested by Pierre in the bug tracker discussion. We must not be paranoidevil about the provided input length "giving away" the answer to the student, just practical that input length should be reasonably long enough to accomodate the longest correct answer (if there are more than one).

case 'shortanswer':
case 'numerical':
// set length of answer input field to length of longest expected answer
$snmaxlen= 0;
foreach ($answers as $snanswer) {
 if (strlen($snanswer->answer) > $snmaxlen){
 $snmaxlen = strlen($snanswer->answer);
 }
}
if ($snmaxlen<6){ $snmaxlen= 6; }

Joseph