Date picker can't display well when on click
Lipchen92 opened this issue · 1 comments
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(),
from_picker = 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';
}
}
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