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

Provide 'remove' option #59

Open
adam-lynch opened this issue Jan 24, 2013 · 2 comments
Open

Provide 'remove' option #59

adam-lynch opened this issue Jan 24, 2013 · 2 comments

Comments

@adam-lynch
Copy link

$('#timepicker-input').timepicker('remove') would be nice.

I was troubleshooting an issue where we having where we add inputs to the DOM, initialize the timepicker on them, then remove them from the DOM, then add some other inputs to the DOM, initialize the timpicker on them... then the timepicker would show but a click on a date wouldn't do anything.

That isn't the reason for this issue. I decided to completely remove the timepicker when the inputs are removed from the DOM*, and the best way I found to achieve this was the following:

//remove timepicker div
$($.timepicker._tpDiv).remove();

//unbind all related events
$($elem).find('.has-timepicker').unbind('.timepicker');

/*
$.fn.timepicker is subscribed to the mousedown event for the whole document (default event; no namespace)
so we can't undo that but when that event is triggered they first check if there's an instance of the
timepicker ($.timepicker._curInst)
*/

//reset timepicker settings; tell it there's no timepicker instance
$.timepicker._curInst = false;

It would've been much nicer if I could've just had $($elem).find('.has-timepicker').timepicker('remove') or (because the former is per field) $.timepicker.remove() to completely remove the timepicker instance and event handling.

* - well, when the modal they're in is hidden actually (the hidden modal will never be used again, it will most likely be replaced by another modal containing other inputs)

@fgelinas
Copy link
Owner

Hi,
There is actually a "destroy" option that remove the timepicker classes from the input and unbind events : $($elem).timepicker('destroy'); should work.
It will not unset the _curInst because the function _destroyTimepicker function does not check if it is currently showing. However if the user click a close button or something outside a showing timepicker, The _hideTimepicker will be called and the _curInst will be set to null.

@adam-lynch
Copy link
Author

Sorry, must've missed that in the documentation.

Sounds good. I'll swap out my code for this next week and let you know if anything unexpected happens.

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