daterangepicker 一些操作不便的修復(fù)

一.前言
最近在優(yōu)化項(xiàng)目前端,老板非想要一個(gè)時(shí)間范圍的選擇,覺得用兩個(gè)時(shí)間輸入框操作不便??吹骄W(wǎng)上有三種:分別是mobiscroll,用于手機(jī)端;jquery下的插件 Date Range Picker;基于bootstrap的daterangepicker。看了下官方文檔,Date Range Picker和daterangepicker樣子差不多。想著項(xiàng)目大體用的bootstrap,那就用daterangepicker吧。結(jié)果發(fā)現(xiàn)好多操作不便的小問題(不知道是不是我操作方式奇葩。。。)。善始善終,那就改源碼吧。
二、小bug修復(fù)
1.輸入框默認(rèn)值為當(dāng)前時(shí)間,可我們要自己的提示咋辦,"autoUpdateInput":false可以做到,但是,它居然讓輸入框一直都沒值,這就不好了。百度了下,機(jī)智的網(wǎng)友給出了解決方案,在某些地方,設(shè)置autoUpdateInput為true。
a. clickRange方法修改成如下:
} else if (!this.endDate && date.isBefore(this.startDate)) {
this.autoUpdateInput = true;
//special case: clicking the same date for start/end,
//but the time of the end date is before the start date
this.setEndDate(this.startDate.clone());
} else { // picking end
this.autoUpdateInput = true;
var dates = this.ranges[label];
this.startDate = dates[0];
this.endDate = dates[1];

            if (!this.timePicker) {
                this.startDate.startOf('day');
                this.endDate.endOf('day');
            }

            if (!this.alwaysShowCalendars)
                this.hideCalendars();
            this.clickApply();
        }
b.clickDate方法中增加
  } else if (!this.endDate && date.isBefore(this.startDate)) {
            this.autoUpdateInput = true;
            //special case: clicking the same date for start/end,
            //but the time of the end date is before the start date
            this.setEndDate(this.startDate.clone());
        } else { // picking end
            this.autoUpdateInput = true;

2.打開日期控件后,點(diǎn)擊外邊空白處以及選了時(shí)間,但是沒有點(diǎn)“確定”而是點(diǎn)”取消“后,時(shí)間控件輸入框會(huì)寫入時(shí)間。
a.clickCancel方法注釋掉this.hide(),改成以下代碼:
if (this.isShowing){
$(document).off('.daterangepicker');
$(window).off('.daterangepicker');
this.container.hide();
this.element.trigger('hide.daterangepicker', this);
this.isShowing = false;
}
b.outsideClick方法中也像上面那樣將this.hide()改掉
c.show方法中,改成如下,注釋掉的為原來的,下面是新增的
// this.oldStartDate = this.startDate.clone();
// this.oldEndDate = this.endDate.clone();
// this.previousRightTime = this.endDate.clone();

        this.oldStartDate = this.startDate;
        this.oldEndDate = this.endDate;
        this.previousRightTime = this.endDate;

3.鼠標(biāo)移到日期選擇的某個(gè)日期時(shí),上面對應(yīng)的輸入框的值也會(huì)跟著一直變化,但是當(dāng)我選擇了兩個(gè)日期后,鼠標(biāo)再移在上面,還變化就不好了,讓我以為上面開始時(shí)間和結(jié)束時(shí)間輸入框數(shù)據(jù)出了問題,所以一氣之下,去掉了這個(gè)特性。
hoverDate方法中,將下面兩行注釋掉(以下代碼我注釋的部分就是):
if (this.endDate && !this.container.find('input[name=daterangepicker_start]').is(":focus")) {
// this.container.find('input[name=daterangepicker_start]').val(date.format(this.locale.format));
} else if (!this.endDate && !this.container.find('input[name=daterangepicker_end]').is(":focus")) {
// this.container.find('input[name=daterangepicker_end]').val(date.format(this.locale.format));
}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,590評論 19 139
  • afinalAfinal是一個(gè)android的ioc,orm框架 https://github.com/yangf...
    passiontim閱讀 15,879評論 2 45
  • 1. Java基礎(chǔ)部分 基礎(chǔ)部分的順序:基本語法,類相關(guān)的語法,內(nèi)部類的語法,繼承相關(guān)的語法,異常的語法,線程的語...
    子非魚_t_閱讀 34,734評論 18 399
  • 斯人一去不復(fù)返, 昨日舊情隨煙飛。 耳畔山盟似譏語, 怨芳菲, 情深卻阻阮郎歸。
    五月慕晴閱讀 341評論 0 2
  • 明天就是一年一度的教師節(jié)了,相信許多在校學(xué)生已經(jīng)在想明天要怎么給自己的恩師表白了,或者禮物都已準(zhǔn)備好就等明天送出去...
    行走的小熊閱讀 415評論 0 0

友情鏈接更多精彩內(nèi)容