jquery-uidatepickerfancybox

jqueryUI datepicker in fancybox does not work


I have this strange problem. When I put an input with datepicker class into a fyncybox wrap, datepicker does not show up when I click on that input.

<a href="#test" class="fancybox">Open</a>
<div id="test" style="display:none;width:300px;">
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque blandit, mi sed
</p>
<input type="text" class="datepicker"/>
</div>

$(".datepicker").datepicker();

$(".fancybox").fancybox({
    openEffect  : 'none',
    closeEffect : 'none',
    afterLoad   : function() {
        this.inner.prepend( '<h1>1. My custom title</h1>' );
        this.content = '<h1>2. My custom title</h1>' + this.content.html();
    }
});

See this example on fiddle.

Thanks in advance ;-)


Solution

  • Hi I have eventually found these two solutions:

    FIRST: fiddle of first solution here

    $(document).on('click', '.datepicker', function(){ 
        if (!$(this).hasClass('hasDatepicker')) { 
            $(this).datepicker(); $(this).datepicker('show'); 
        }
    }); 
    
    $(".fancybox").fancybox({
        openEffect  : 'none',
        closeEffect : 'none',
        afterLoad   : function() {
           this.inner.prepend( '<h1>1. My custom title</h1>' );
           this.content = '<h1>2. My custom title</h1>'+ this.content.html();
        }
    });
    

    SECOND: fiddle of second solution here

    $(".datepicker").datepicker();
    
    $(".fancybox").fancybox({
       openEffect  : 'none',
       closeEffect : 'none'
    });