-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Remove listen changeDate
after destroy DateRangePicker
#1968
Conversation
@@ -1567,6 +1567,7 @@ | |||
}, | |||
destroy: function(){ | |||
$.map(this.pickers, function(p){ p.destroy(); }); | |||
$(this.inputs).off('changeDate', this.dateUpdated); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.dateUpdated
!== $.proxy(this.dateUpdated, this);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. But it is work for jQuery. From docs:
When jQuery attaches an event handler, it assigns a unique id to the handler function. Handlers proxied by jQuery.proxy() or a similar mechanism will all have the same unique id (the proxy function), so passing proxied handlers to .off may remove more handlers than intended. In those situations it is better to attach and remove event handlers using namespaces.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
И чего?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/eternicode/bootstrap-datepicker/blob/master/js/bootstrap-datepicker.js#L2001 используется нэймспейс. Я считаю что лучше использовать нэймспейс, даже jQuery советует.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the way of removing events to namespace.
You need to add namespace here (https://github.com/eternicode/bootstrap-datepicker/blob/master/js/bootstrap-datepicker.js#L1513) and add testcase. |
I added namespace. |
@acrobat Let's roll out without tests. Namespace is not necessary. |
@lusever Can you remove the |
@acrobat I removed namespaces. |
If I use the code which is currently: $('.inputs input').on('changeDate', myFunc)
$('.inputs').datepicker({inputs: $('input')})
$('.inputs').data('datepicker').remove(); // removed myFunc too I think the original version is more correct. It is like in |
So the changes in this PR are not correct @lusever? |
@acrobat now is correct. |
Thanks @lusever! |
Need for correct recreate DateRangePicker on same inputs.