sp-container not destroyed when boundElement is removed from DOM
Hello, I've been trying your (very nice) colour picker within a w2ui grid. The grid is created with <input> elements for each picker and then they are bound using $( picker ).spectrum( { ... } ). So the boundElement is rendered into the DOM when the grid is shown and removed when the grid is hidden, but the .sp-container is not removed from the DOM. Should it be auto-removing itself when the boundElement is removed, or do I have to do that manually?
Thanks, and much respect for your work.
Hi, generally you'll have to remove it manually with $(picker).spectrum("destroy"). I think detecting all the situations where it gets removed and cleaning up would be tricky (although maybe possible with a Mutation Observer).
Hello -- kind of got wrapped up for a week (or five) there. Thanks for the reply. I had tried that, but for a moment after the control is destroyed the underlying control is shown. So instead, prior to removing $( picker ) from the DOM, I used:
container = $( picker ).spectrum( 'container' );
$( container ).remove();
then allow $( picker ) to handle itself when it's removed from the DOM. Works nicely.
I only asked about auto-removing itself after I learned about jQuery UI widgets and discovered those have their own _destroy handler.
Thanks again.