Add a rich text editor in a popup (dialogue)

Add a rich text editor in a popup (dialogue)

by Marie-Eve Lévesque -
Number of replies: 1
Picture of Core developers Picture of Plugin developers

Is there a way to add a rich text editor to a popup (dialogue) that uses ajax?

I already have a popup with a form in it, the form can be saved correctly in ajax. I would now like to replace a regular textarea with a rich text editor (like atto). As I don't have access to a mform in this popup I haven't found a solution yet.

I have been able to get the html of a MoodleQuickForm_editor form element via a webservice but it only displays a regular textarea. The javascript probably isn't called for the popup, to initialise the RTE. I tried to add some direct calls to Y.M.editor_atto.Editor.init in the javascript of the mustache template for my popup but I only got errors because Y.M.editor_atto does not exist.

So is there a way to add a rich text editor in a popup? And once I have the editor, would it be possible to handle file uploads? (the form is saved via ajax)

Average of ratings: -
In reply to Marie-Eve Lévesque

Re: Add a rich text editor in a popup (dialogue)

by Mark Johnson -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

You probably want to look at the Fragment module.

The idea is that you create a function that renders and returns your form. You then use the fragment module to call this function via a special AJAX call. Moodle does some magic to return the HTML and Javascript separately, so that they can be loaded into the page in the right order, and the atto editor can be correctly initialised.

Average of ratings: Useful (1)