R
R
Robert2015-09-08 20:36:31
JavaScript
Robert, 2015-09-08 20:36:31

Why does the text editor in the form disappear?

I use wysiwyg editor in my form.
Everything works great.
The site has an "Edit" link, clicking on which sends an ajax request to the edit action of the controller.
The content of the edit.js.erb file is:

$('#place-content').html('<%= escape_javascript( render partial: "form", locals: {place: @place} )%>')

That is, by clicking on this button, my form is rendered into the block.
The problem is that in this case the wysiwyg editor does not appear, but just a normal form appears. What could be the snag?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Vsk, 2015-09-09
@Jowan

There is no problem. It's just that you obviously don't reinitialize the editor after inserting it into the form's DOM.
Most likely, during the first rendering of the page, the following steps take place:
1. The page with the usual form is rendered
2. At the end (or on the document->ready event), the editor is initialized and the form becomes wysiwig
3. Everything happens so quickly that the moment the form transitions to wysiwig you are not watching.
When loading via AJAX, you insert the form, but the code that initializes the editor is nowhere to be found.
Outputs:
1. Cause some event when the DOM changes in the place where you insert the form. And then you can put this code in assets
2. Right in the partial given in the question, add editor initialization
Most of the time, option #2 is preferred.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question