imjp
imjp

Reputation: 6695

jQueryUI's Datepicker doesn't disappear when a date is chosen

Please take a look at http://jsfiddle.net/4bML8/

Everything is working fine (i think) except the fact that the datepicker doesn't disappear when I pick a date. Can anyone tell me what is causing this?

Upvotes: 1

Views: 5082

Answers (2)

muthu
muthu

Reputation: 5461

You never declared the variable dates but you used it. Create a variable dates and check this code

 var dates = $('#d_date, #a_date').datepicker({
            numberOfMonths: 1,
           minDate: +1,
            dateFormat: 'd / m / yy',
            onSelect: function( selectedDate ) {
                var option = this.id == "from" ? "minDate" : "maxDate",
                    instance = $( this ).data( "datepicker" ),
                    date = $.datepicker.parseDate(
                        instance.settings.dateFormat ||
                        $.datepicker._defaults.dateFormat,
                        selectedDate, instance.settings );
                dates.not( this ).datepicker( "option", option, date );
            }
        }); 

Upvotes: 1

dnagirl
dnagirl

Reputation: 20456

If you want the datepicker to close after it enters a date, you need to tell it to move focus out of the current field. I do it this way:

    $.datepicker.setDefaults({ 
                       dateFormat: 'yy-mm-dd', 
                       firstDay: 1,
                       changeMonth:true,
                       changeYear: true,
                       onClose: function(dateText, inst) {
                            $(this).focus(); //set focus and then move to next field so validator will fire
                            $(this).focusNextInputField(); //causes datepicker to close
                        }
    });

Upvotes: 0

Related Questions