Default text in Atto editor

Default text in Atto editor

by Clem Smith -
Number of replies: 3

Hi, I have a form that currently has a simple textarea in it. It has been decided to make this into an Atto editor so the users can pretty-up the text with styling and HTML content. There is a default string that gets populated into this textarea currently. However, when I change this to be an Atto editor, that default string is not preserved after the javascript converts the textarea into an editor. Any help in figuring out how to do this would be appreciated.

Average of ratings: -
In reply to Clem Smith

Re: Default text in Atto editor

by Damyon Wiese -

If the textarea has a value before atto "enhances" it - atto will show the value. This is just a standard mform element so it can have a value or a default and the value will override the default if both are present. The value is picked from the _GET and _POST and the default is specified in the mform. Often people use the "default" for the current value which is not the correct way to do it (the correct way is with set_data on the mform). What can happen is that Atto autosave can kick in and make it a bit confusing - if you don't want autosave for your textarea you can pass "autosave = false" as an option to the textarea when it's added to the mform. 

In reply to Damyon Wiese

Re: Default text in Atto editor

by Clem Smith -

Well, I guess I'm going to need some help with this, then, because after looking at the documentation (both on moodle.org and in the code) and monkeying around with the code, I have still managed not to resolve the problem. This is the code I've got:

$mform->addElement('editor', 'approvenotice', get_string('coursereasonforapprovingemail', 'local_course'), array('rows'=>'15', 'cols=>'50', 'autosave'=>'false'));

$mform->setType('approvenotice', PARAM_RAW);

$mform->setDefault('approvenotice', $message);

And still the value of $message does not display once the textarea has been enhanced by Atto, yet it will if I do not enhance it. So, what am I doing wrong? I've even tried "moodleform::set_data()" and still no juju in skyflower.

In reply to Damyon Wiese

Re: Default text in Atto editor

by Clem Smith -

I should add that I have tried

moodleform::set_data(array('approvenotice' => $message));

and also

$this->set_data(array('approvenotice' => $message));

I have tried these things both with and without autosave set to false and both with and without "false" (single-) quoted.