Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Lipchen92 opened this issue Jun 24, 2022 · 1 comment
Open

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

Lipchen92 opened this issue Jun 24, 2022 · 1 comment

Comments

@Lipchen92
Copy link

Lipchen92 commented Jun 24, 2022

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';
    }

}
@ufku-ate
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants