Friday, April 30, 2010
Cloning jQuery UI datepicker
In case you were having problems with cloning fields with jQuery UI datepicker attached to them - solutions mentioned in the interwebs are similar to this one:
$('.cloned-input').removeClass('hasDatepicker').datepicker();
However, that did not work for me. If you happen to have a set of similar symptoms: - new datepicker is not instantiated at all
- JS errors occur while instantiating new datepicker
- even if datepicker is cloned, it refers to the old field
Solution
Either imitate datepicker('destroy') manually:$input = $('.cloned-input');
// remove still present related DOM objects
$input.siblings('.ui-datepicker-trigger,.ui-datepicker-apply').remove();
// remove datepicker object and detach events
$input
.removeClass('hasDatepicker')
.removeData('datepicker')
.unbind()
.datepicker();
or implement a different procedure:- before cloning destroy the datepicker on the base input
- clone(true)
- recreate the datepicker on base input
- use unbind() and recreate datepicker on cloned input
Subscribe to:
Post Comments (Atom)
2 comments:
Many tks!
Hi,
Can you please provide reference example so that I can better understand. I've use clone(true) and calendar is not working for cloned text fields.
Post a Comment