简体   繁体   中英

Weird Datepicker behaviour, related to blur

I'm completly stuck with Datepicker. Blur hides calendar if Datepicker was active, but focus still stays in input, so I can't trigger datepicker again by clicking to input again. Only 2 datepickers on the page works fine, all other broken this way.

This is how I set datepickers. First pair works fine, second is broken.

dates.intervalDatepickersSet( $( ".head-from, .head-to" ) );
dates.intervalDatepickersSet( $( ".residence-from, .residence-to" ) );

This is the dates.intervalDatepickersSet:

intervalDatepickersSet: function( el ) {
    var interval, i,
    pair = [];

    if ( el.length > 2 ) {
        var elementsContainer = el.toArray();
        for ( i in elementsContainer ) {
            if ( elementsContainer.hasOwnProperty( i ) ) {
                pair[0] = elementsContainer.shift();
                pair[1] = elementsContainer.shift();
                // If we are on the Update order page, we could have few elements with same classes.
                // Set datpickers for each pair of that incoming bundle of   elements.
                dates.intervalDatepickersSet( $( pair ) );
            }
        }
    }

    interval = el.datepicker({
        onSelect: function( selectedDate ) {
            var prefix = dates.prefixFromTo( $( this ) ),
            option = ($(this).hasClass(prefix + '-from')) ? "minDate" : "maxDate",
            instance = $( this ).data( "datepicker" ),
            date = $.datepicker.parseDate(
                instance.settings.dateFormat || $.datepicker._defaults.dateFormat,
                selectedDate, instance.settings);
            interval.not( this ).datepicker( "option", option, date );
            /* calculations code */
    });
}

What is wrong with this?

UPD First working pair of elements:

<input id="id03" class="disable text from head-from" default="__.__._____" type="text" name="Order[z_start_date]" id="z_start_date" value="<?php if($this->getAction()->getId()=="create") echo '__.__._____'; else echo Yii::app()->dateFormatter->format('dd.MM.yyyy', $model->z_start_date);?>" />
<input id="id04" class="disable text to head-to" default="__.__._____" type="text" name="Order[z_end_date]" id="z_end_date" value="<?php if($this->getAction()->getId()=="create") echo '__.__._____'; else echo Yii::app()->dateFormatter->format('dd.MM.yyyy', $model->z_end_date);?>" />

Second broken pair:

<input class="text dateOfSettlement1 residence-from" type="text" name="<?php echo $model->getAttrName($block, 'in'); ?>" value="Дата начала" default="Дата начала" />
<input class="text dateOfEviction1 residence-to" type="text" name="<?php echo $model->getAttrName($block, 'out'); ?>" value="Окончание" default="Окончание" />

UPD2

I can trigger datepicker again only when i clicked to another input or drag some element (trigger another action). What can be the reason of that behaviour?

So I can only trigger datepicker again after "focusout" event, but not after "blur". Though, calendar hides on blur.

Checkout the datepicker showOn option. docs

You probably want to set it to "both". By default it is set to "focus" which won't trigger again if the input element still has focus.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM