Semantic-Org / Semantic-UI

Semantic is a UI component framework based around useful principles from natural language.
http://www.semantic-ui.com
MIT License
51.11k stars 4.94k forks source link

[Components] How do you cleanup bindings on select (and others) when rerendering dom elements manually? #6379

Open StupidIncarnate opened 6 years ago

StupidIncarnate commented 6 years ago

[Components] How do you cleanup bindings on select (and others) when rerendering dom elements manually?

Steps

I'm using backbone so I manually build and rerender dom sections repeatedly. I figured out how to manually bind to a select to give it the events it needs, but when I rerender the view, it's giving this error, so I'm wondering how do I clean up these event bindings before I rerender.

image

I tried these but neither seems to get rid of the attachment error: image

I know it says to just disable the warning, but I would like to clean them up if possible so there's not straggler events on the dom.

Expected Result

To be able to unbind select events from dom so nothing lingers when the dom element is rerendered.

Actual Result

It's throwing a binding event error when I rerender a dom partial.

Version

2.3.1

y0hami commented 6 years ago

This is because dropdowns use the transition module https://semantic-ui.com/modules/transition.html and it requires it to be attached to the DOM.

Try disabling the transition using the dropdown settings https://semantic-ui.com/modules/dropdown.html#/settings

StupidIncarnate commented 6 years ago

Like so?

image

If I do that I get double the error right when I try to click on it, even before rerendering. stop instead of stop all does the same.

image

I'm fine with it attaching to the dom, and I like the transition. I'm more looking for if there's a way to clean up that dom connection if I rerender so it can reattach when the element gets redrawn.

It looks like if I give it a unique name, it doesn't throw that dom error when it rerenders. I assume because it rehooks up based on that name, rather than a random binding without the name?

image