jQuery Datepicker: Prevent closing picker when clicking a date

后端 未结 9 2209
南方客
南方客 2020-11-29 08:16

Hi fellow stackoverflow:ers,

I\'m using the jQuery Datepicker plugin, together with Martin Milesich Timepicker plugin. Everything works great, except for the fact th

9条回答
  •  天命终不由人
    2020-11-29 09:01

    You should override native js function:

     /* Update the input field with the selected date. */
            _selectDate: function(id, dateStr) {
                var target = $(id);
                var inst = this._getInst(target[0]);
                dateStr = (dateStr != null ? dateStr : this._formatDate(inst));
                if (inst.input)
                    inst.input.val(dateStr);
                this._updateAlternate(inst);
                var onSelect = this._get(inst, 'onSelect');
                if (onSelect)
                    onSelect.apply((inst.input ? inst.input[0] : null), [dateStr, inst]);  // trigger custom callback
                else if (inst.input)
                    inst.input.trigger('change'); // fire the change event
                if (inst.inline)
                    this._updateDatepicker(inst);
                else {
                    if(inst.settings.hideOnSelect != false){
                        this._hideDatepicker();
                    }
                    this._lastInput = inst.input[0];
                    if (typeof(inst.input[0]) != 'object')
                        inst.input.focus(); // restore focus
                    this._lastInput = null;
                }
            },
    

    And add appropriate option to datepicker configuration, as example:

    var defaultDatePickerOptions = {
            hideOnSelect: false,
            ...
        }; 
     var birthDate = jQuery.extend({}, defaultDatePickerOptions);
     $('#birthdate').datepicker(birthDate);
    

提交回复
热议问题