Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Component is losing mouse events after replace content with AJAX #923

Open
gilsondelrei opened this issue May 29, 2019 · 2 comments
Open

Comments

@gilsondelrei
Copy link

Hi all.
I'm experiencing a problem with losing events when replacing content from ajax. Well, it isn't an ajax problem, but i have some dynamic contents and need replace the html slider tag when i update the container DIV with other informations.

It's my process:
1 - First i get the original content of container including the bootstrap-slider component generated tags. The content is like sample below. Its my container_recovered_content

<div` class="slider slider-horizontal" style="width: 220px;">
    <div class="slider-track">
    <div class="slider-selection" style="left: 0%; width: 44.4444%;"></div>
    <div class="slider-handle round" style="left: 44.4444%;"></div>
    <div class="slider-handle round hide" style="left: 0%;"></div>
</div>
<div class="tooltip top" style="top: -40px; left: 50.7778px;">
    <div class="tooltip-arrow"></div>
    <div class="tooltip-inner">Current value: 5</div></div>
    <input type="text" id="sl1" class="col-md-12" value="1" data-slider-min="1" data-="" slider-max="20" data-slider-value="5" style="">
</div>

2 - After i call a ajax process and replace all components on my DIV container (not in example) with new content.
3 - User click on back button and the original content (item 1) is recovered and replaced in place.

$("#container').html(container_recovered_content).

at now the slider component is rendered, but component slider is freezed. In other words, it doesn't response for any mouse events. 

I have observed on Chrome that after replaced the content the mouse events initially binded was unbinded on component.

Tests:
I have generated a Fiddle (http://jsfiddle.net/gildlrei/yxj9m4p8/84/) and some details to execute the fiddle. It's not ajax example, but enough to evidence the problem.

On my sample test there are three buttons that you can try in sequence as below.

1 - First click on [generate content] button. It will got the original slider html generated and display it on the bottom. Additionally it will replace the container DIV with the text "nothing here" erasing the slider component.

2 - Click on [replace content] button. It will return the original content and re-rendering the slider component. At this point you can see that slider is freezed.

3 - Click on [start new instance of Slider] button. It will call the Slider() function on my selector slider $('#sl1') trying to reinitialize it. At this point you can see two components, the last one is working.

One last note about this
Trying to delegate the events to document DOM like below seems not work. It has work with other native events but not with slider.

> $(document).on('slide slideStop','#slide_distance', function (e) {
...
});

Try reinitialize the component Slider using the Slider() function has generated a new instance (duplicate) component on DIV.

$(#sl1).Slider({...})

Thanks any suggestions

@seiyria
Copy link
Owner

seiyria commented May 29, 2019 via email

@gilsondelrei
Copy link
Author

gilsondelrei commented May 29, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants