Setting Default Value to Editor (already tried some code without success)

Setting Default Value to Editor (already tried some code without success)

by Pablo Escobar -
Number of replies: 4
Hi, i already tried this code to set the default value to an editor without success
$mform->addElement('editor', 'introeditor', get_string('moduleintro'), array('rows' => 10), array('noclean' => true, 'context' => $context, 'subdirs' => true));
$mform->setDefault('introeditor', array('text'=>'Default text!', 'format' => FORMAT_HTML));
$mform->setType('introeditor', PARAM_RAW);
And this code to:
$mform->addElement('editor', 'introeditor', get_string('moduleintro'), array('rows' => 10), array('noclean' => true, 'context' => $context, 'subdirs' => true))->setValue( array('text' => 'Default text!') );
Any other suggestion to set the default value of an editor?

Thanks in advance
Average of ratings: -
In reply to Pablo Escobar

Re: Setting Default Value to Editor (already tried some code without success)

by Luuk Verhoeven -
Picture of Core developers Picture of Plugin developers

You could do something like this:

$form = new Yourform();

$form->set_data(['introeditor' => ['text' => 'Default text!' , 'format' => FORMAT_HTML]);

Hope this helps.

In reply to Luuk Verhoeven

Re: Setting Default Value to Editor (already tried some code without success)

by Pablo Escobar -

Thanks for ur reply,

I use that code but i am getting the following fatal error:

Fatal error: Call to undefined method MoodleQuickForm::set_data()

Greetings

In reply to Pablo Escobar

Re: Setting Default Value to Editor (already tried some code without success)

by Luuk Verhoeven -
Picture of Core developers Picture of Plugin developers

Your class extends moodleform?

 extends \moodleform {
In reply to Luuk Verhoeven

Re: Setting Default Value to Editor (already tried some code without success)

by Pablo Escobar -

My class extends moodleform_mod, but i do the trick with javascript.


$mform->addElement('static', null, '',
                    '<script type="text/javascript">
            //<![CDATA[
                jQuery(document).ready(function() {
                    jQuery("#id_introeditor").html("default text!");
                });
            //]]>
            </script>');