I'm trying to apply a datepicker control to cloned input fields. What I'm doing is finding the table row I want to clone, clone it with clone(false)
and then for each input with a class .date
call datepicker()
on them. The code is as follows:
$('.repeat').bind('click', function() {
var parentEl = $(this).parents('.root');
var lastRow = jQuery.makeArray($(parentEl).find('.last'));
var newRow = $(lastRow).clone(false);
$(lastRow).removeClass('last');
$(newRow).addClass('last');
newRow.find('input').each(function() {
this.name = this.name.replace(/\[(\d+)\]/, function(str, p1) {
return '[' + (parseInt(p1, 10) + 1) + ']';
});
}).end().insertAfter($(lastRow));
newRow.find('.date').each(function() {
$(this).removeAttr('id');
$('.date').datepicker({ dateFormat: 'dd-mm-yy', changeYear: true, yearRange: '1970:2010' });
});
});
Now both $(this).datepicker()
and $('.date').datepicker()
fail to attach a datepicker control to input.date
.
The above code works as expected except for the datepicker bit.
Anybody have any ideas?!