Editor template remains in dom after editor.destroy()

Editor template remains in dom after editor.destroy()

hserveirahserveira Posts: 7Questions: 4Answers: 0

After destroying an editor instance, the custom template defined on the configuration is remains into the dom. I'm following this example:
https://editor.datatables.net/examples/simple/template.html

I tried creating a test case on https://live.datatables.net/ but I'm getting an error when inserting the DataTables Editor library.

To solve this, a simple template.remove() is enough, but I assume editor.destroy() should take care of that? Or maybe I am doing something wrong?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 22,200Questions: 26Answers: 5,111

    Here is a simple test case:
    https://live.datatables.net/guwafemu/640/edit

    In the test case using destroy() doesn't remove the template. This is in the destroy() docs.

    It will clean up any events added by Editor, fields and DOM elements.

    It's not perfectly clear but I read this to mean that destroy() will remove anything the Editor library adds to the page. The template, while used by Editor, is not added by the Editor. You may want to use the template with another Editor instance.

    @allan can comment on whether he feels this is correct behavior.

    Kevin

  • allanallan Posts: 64,829Questions: 1Answers: 10,731 Site admin
    edited July 29 Answer ✓

    Many thanks for creating the test case Kevin.

    Yes, I think I am happy with the current behaviour. Part of the idea there is that if you need to create a new instance and reference to the same template, the only way to do that would be to have the template element in the DOM.

    As you say, a call to .remove() immediately after .destroy() on the Editor instance will do it.

    Allan

Sign In or Register to comment.