Search code examples
polymerclonenode

Polymer - cloneNode including __data


I am using the library dragula for doing some drag & drop stuff.

Dragula internally uses cloneNode(true) to create a copy of the dragged element that will be appended to the body to show the preview image while dragging.

Unfortunately, if dragging a polymer element, the bound data get's not cloned. By consequence the contents of the dragged element (e.g. <div>[[someString]]</div>) are empty.

Is there a solution for this?

I actually do not need the data to be bound for my element, it is just a "read-only" element that displays some data that does not change after being initialized. Is there maybe a way to somehow "resolve" the strings to the html without being bound anymore?

Thank you already!


Solution

  • Found a solution myself. You have to override the cloneNode method inside the polymer class:

    cloneNode(deep) {
      let cloned = super.cloneNode(deep);
      for (let prop in MyClass.properties) {
        cloned[prop] = this[prop];
      }
      return cloned;
    }