[Answer]-Apply tinyMCE settings to dynamicly created textarea

1đź‘Ť

âś…

Change the id for each textarea. ids are supposed to be unique in HTML, but your for loop is creating multiple textareas with the same id. TinyMCE is trying to render the textarea with id=”tobs” and gets confused when it finds more than one. You could try:

{% for obs in obss %}
    ...
    {% with "tobs"|add:forloop.counter as area_id %}
        <textarea id={{ area_id }} class="ro">{{ obs.description }}</textarea<br>
    {% endwith %}
    ...
{% endfor %}

That should make your textareas with ids: tobs1, tobs2, tobs3,…, which should fix the problem.

Read more here: https://docs.djangoproject.com/en/dev/ref/templates/builtins/#for

And here: TinyMCE not working when loading two textareas

But there should be a more elegant solution to this problem. So far I’ve been able to find this example, which uses class to distinguish between textareas and doesn’t use ids at all, which contradicts the solution from the last link: http://www.tinymce.com/tryit/3_x/multiple_configs.php

👤Nagra

Leave a comment