amsul / pickadate.js

The mobile-friendly, responsive, and lightweight jQuery date & time input picker.
http://amsul.ca/pickadate.js
MIT License
7.7k stars 1.02k forks source link

Date picker can't display well when on click #1241

Open Lipchen92 opened 2 years ago

Lipchen92 commented 2 years ago

When click on the date picker, it sometimes flash but did not popup. It seem showed but immediately close down. Would like to know how to solve this.

/html/

            <div class="date-wrap">
               <p>From Date:</p>
                <div class="datepicker-bg"><input type="text" id="fromDate" onclick="getTime('start');" maxlength="50" class="txt-ipt" placeholder="From Date"/><i></i></div>
            </div>
            <div class="date-wrap">
               <p>To Date:</p>
               <div class="datepicker-bg"><input type="text" id="toDate" onclick="getTime('end');" maxlength="50" class="txt-ipt" placeholder="To Date"/><i></i></div>
            </div>

/jquery/ $(document).ready(function() { /date picker/ /from date/ var from_$input = $('#fromDate').pickadate(), frompicker = from$input.pickadate('picker')

    /*to date*/
    var to_$input = $('#toDate').pickadate(),
    to_picker = to_$input.pickadate('picker')

    // Check if there’s a “from” or “to” date to start with.
    if ( from_picker.get('value') ) {
        to_picker.set('min', from_picker.get('select'))
    }
    if ( to_picker.get('value') ) {
        from_picker.set('max', to_picker.get('select'))
    }

    // When something is selected, update the “from” and “to” limits.
    from_picker.on('set', function(event) {
        if ( event.select ) {
            to_picker.set('min', from_picker.get('select'))    
        }
        else if ( 'clear' in event ) {
            to_picker.set('min', false)
        }
    })
    to_picker.on('set', function(event) {
        if ( event.select ) {
            from_picker.set('max', to_picker.get('select'))
        }
        else if ( 'clear' in event ) {
            from_picker.set('max', false)
        }
    })

});

function getTime(value){
    if (value == 'start') {
        currentStart = $('#fromDate').val() +' 00:00:00';
    }else if(value == 'end') {
        currentEnd = $('#toDate').val() +' 23:59:59';
    }

}
ufku-ate commented 2 months ago

This can be observed by performing a slow click. When you hold down the mouse click button for 1 sec and release it, the date popup opens(on mousedown), then disappears(on mouseup). This is because the document.click event triggers just after the popup open and is detected as an outside click and closes the popup.

The solution is to use document.mousedown instead of document.click.

Change $document.on( 'click.' + STATE.id + ' focusin.' + STATE.id, function( event ) { with $document.on( 'mousedown.' + STATE.id + ' focusin.' + STATE.id, function( event ) { in picker.js

And change .on("click."+ with .on("mousedown."+ in compressed/picker.js