Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

datepicker in JQuery UI Dialog shows calendar on dialog open

I have a JQuery modal dialog with 2 JQuery UI datepicker inputs. My problem is that when the dialog opens the calendar is already open on the page. I am not sure if this is because it is getting focus but the net result is that it shows on dialog open. Here is my code:

<script type="text/javascript">

        $(function() {
            $('input').filter('.datepicker').datepicker({
                changeMonth: true,
                changeYear: true
            });
        });

</script>

<div id="rpt_dialog" title="">
    <form id="rptDlgForm"  action="/EquipTrack/ShowReport" method="post">         
    <center>
    <div id="rpt_dlg_results"></div>
    </center>
    <div style="float:left; padding-left:50px">From:</div>
    <input  class="datepicker" id="dtReportFrom" name="dtReportFrom" type="text" style="float:left">
    <div style="float:left; padding:0 5px 0 15px">To:</div>
    <input class="datepicker" id="dtReportTo" name="dtReportTo"  type="text" style="float:left">
    <br />
    <br />
    <p><input type="submit" value="Show report" id="btnSubmit" style="float:left;padding-right:10px"/> 
    <input type="button" onclick="CloseReportDialog()" value="Close" id="Button2" /></p>
    <p></p> 
    <input type="hidden"  id="hdnReportName" name="hdnReportName" value=""/>
    </form>         
</div>
like image 857
MikeD Avatar asked Nov 25 '09 19:11

MikeD


People also ask

How do I fix my datepicker position?

To change the position of the jQuery UI Datepicker just modify . ui-datepicker in the css file. The size of the Datepicker can also be changed in this way, just adjust the font size.

How do I know if my datepicker is open?

datepicker(). on("show", function () { isCalendarVisible = true; }).

How datepicker is implemented in jQuery?

The datepicker is tied to a standard form input field. Focus on the input (click, or use the tab key) to open an interactive calendar in a small overlay. Choose a date, click elsewhere on the page (blur the input), or hit the Esc key to close. If a date is chosen, feedback is shown as the input's value.


1 Answers

I got this to work but disabling the datepickers just prior to opening my dialog and then enabling them in the open event of the dialog. Code is:

    $('#dtReportFrom').datepicker('disable');
    $('#dtReportTo').datepicker('disable');


    jQuery('#rpt_dialog').dialog('open');


    $(function() {
        $("#rpt_dialog").dialog({
            bgiframe: true,
            width: 540,
            modal: true,
            autoOpen: false,
            resizable: false,
            open: function(event, ui) {
                $(ui).find('#dtReportFrom').datepicker('enable');
                $(ui).find('#dtReportTo').datepicker('enable');
        },
             close: function(event,ui) {
            }                
        })
    });
like image 136
MikeD Avatar answered Sep 21 '22 21:09

MikeD