I have a problem where jQuery datepicker fails to display the calendar, because something swallows the event. It seems like it might be AngularJS causing the problem. You can see it at: jsfiddle.net example
In the jsfiddle example, I've created one datepicker at the bottom of the page which appears all the time and isn't initialized until you click the [Init DatePicker] button.
Here's the init() method where I initialize the jQuery Datepicker as detailed in jquery docs.
function init(selId)
{
if (console.log !== undefined)
{
console.log("init()...");
}
$(function() {
$( ".datepicker" ).datepicker({
changeMonth: true,
changeYear: true
});
});
if (selId !== undefined)
{
$(".datepickFix").on("click","#" + selId, function (){
$(".datepicker").datepicker( "show" );
});
}
else
{
$(".datepickFix").on("click",".datepickFix", function (){
$(".datepicker").datepicker( "show" );
});
}
}
Try This
Go ahead and click the "edit" box or [click me] text and you'll see that it doesn't display the jQuery Datepicker.
Works As Expected
Now, click the [Init DatePicker] button and again, attempt to click the "edit" box and you'll see the calendar display as you expect. If you click the [click me] text it will also display. Everything works as expected.
ng-repeat - addrow() calls init() However, now click an the [Add Row] button and notice that I am doing an ng-repeat in AngularJS to add rows to a table. The row contains another "datepicker" and the Init() code is called upon adding the row.
I also call init() from the onclick of the div just to make it fire.
The Datepicker Still Doesn't Display
However, notice that even though the init() is called -- confirmed by console.log -- you will see that clicking on the "edit" box (jquery datepicker) in the new row does not display the datepicker.
Now, if you click the [click me] text in the row or you click the [Init DatePicker] the calendar will now show.
Clicking [Add Row] button twice makes the first-added row work, not the other Also, if you click the [Add row] button twice, the calendar will show upon initially clicking the first-added row.
However, if I call init() multiple times that doesn't work either. Can anyone shed some light on this issue?