HTML editor appears only once per page

HTML editor appears only once per page

by Olli Savolainen -
Number of replies: 5
Hi,

I have a fresh install of moodle 1.6.3+, and the wysiwyg editor only gets shown once per page in quizzes with multiple essay questions. When I look at the source, only the first one has the javascript code:
 <table class="answer">
 <tr>
 <td>
 <script type="text/javascript" src="https://***/moo/lib/editor/htmlarea/htmlarea.php?id=2"></script>
<script type="text/javascript" src="https://***/moo/lib/editor/htmlarea/lang/en.php"></script>
<textarea id="edit-resp1_" name="resp1_" rows="18" cols="80"></textarea>
 </td>
 </tr>
 <tr>
 <td class="feedback">
 </td>
 </tr>
 </table>
 </div>
<script language="javascript" type="text/javascript" defer="defer">
editor_e9bb8f59201c483c4e92b6d3a9fe2ce4 = new HTMLArea('edit-resp1_');
var config = editor_e9bb8f59201c483c4e92b6d3a9fe2ce4.config;
config.pageStyle = "body { background-color: #ffffff; font-family: Trebuchet MS,Verdana,Arial,Helvetica,sans-serif; }";
config.killWordOnPaste = true;
config.fontname = {
"Trebuchet": 'Trebuchet MS,Verdana,Arial,Helvetica,sans-serif',
"Arial": 'arial,helvetica,sans-serif',
"Courier New": 'courier new,courier,monospace',
"Georgia": 'georgia,times new roman,times,serif',
"Tahoma": 'tahoma,arial,helvetica,sans-serif',
"Times New Roman": 'times new roman,times,serif',
"Verdana": 'verdana,arial,helvetica,sans-serif',
"Impact": 'impact',
"Wingdings": 'wingdings'};

editor_e9bb8f59201c483c4e92b6d3a9fe2ce4.generate();
</script>
The rest only have like:
<textarea id="edit-resp2_" name="resp2_" rows="18" cols="80"></textarea>
I'm in a hurry with this one, please reply asap, preferably before noon.
Average of ratings: -
In reply to Olli Savolainen

Re: HTML editor appears only once per page

by Olli Savolainen -
As I often seem to be, again this time replying to myself. However, I would still like to understand why moodle seems to deliberately do something that clearly seems like a bug. With the below code I get html_editors for all essay questions, since I comment out the code the purpose of which is stated in the comment to "Only use the rich text editor for the first essay question on a page." What the...?!

function print_question_formulation_and_controls(&$question, &$state, $cmoptions, $options) {
global $CFG;
static $htmleditorused = false;

$answers = &$question->options->answers;
$readonly = empty($options->readonly) ? '' : 'disabled="disabled"';

// Only use the rich text editor for the first essay question on a page.
/*start changes*/
//was: $usehtmleditor = can_use_html_editor() && !$htmleditorused;
$usehtmleditor = can_use_html_editor();
/*end changes*/
$formatoptions = new stdClass;
$formatoptions->noclean = true;
$formatoptions->para = false;

$inputname = $question->name_prefix;
$stranswer = get_string("answer", "quiz").': ';

/// set question text and media
$questiontext = format_text($question->questiontext,
$question->questiontextformat,
$formatoptions, $cmoptions->course);

$image = get_question_image($question, $cmoptions->course);

// feedback handling
$feedback = '';
if ($options->feedback) {
foreach ($answers as $answer) {
$feedback = format_text($answer->feedback, '', $formatoptions, $cmoptions->course);
}
}

// get response value
if (isset($state->responses[''])) {
$value = stripslashes_safe($state->responses['']);
} else {
$value = "";
}

// answer
if (empty($options->readonly)) {
// the student needs to type in their answer so print out a text editor
$answer = print_textarea($usehtmleditor, 18, 80, 630, 400, $inputname, $value, $cmoptions->course, true);
} else {
// it is read only, so just format the students answer and output it
$safeformatoptions = new stdClass;
$safeformatoptions->para = false;
$answer = format_text($value, FORMAT_MOODLE,
$safeformatoptions, $cmoptions->course);
}

include("$CFG->dirroot/question/type/essay/display.html");

if ($usehtmleditor) {
use_html_editor($inputname);
$htmleditorused = true;
}
}

So I got it working now, but I'm afraid of the unknown implications.
In reply to Olli Savolainen

Re: HTML editor appears only once per page

by Colin Western -
A colleague put in a request on the bug tracker for a related feature, and it was turned down as apparently more than one on a page causes problems. It may be related to more general problems - see http://moodle.org/mod/forum/discuss.php?d=58537

In reply to Colin Western

Re: HTML editor appears only once per page

by Olli Savolainen -
Doesn't seem related to me though - the above is clearly a problem with moodle source code, and the problem in your url doesn't seem to be?
In reply to Olli Savolainen

Re: HTML editor appears only once per page

by Paul Baumeister -
I have the same problem with moodle 1.8. Since you fixed it, have you had any problems? Which file did you edit?