From 564037b0a99367ef5acb24e5478aab8fafceef50 Mon Sep 17 00:00:00 2001 From: waki <107737@gmail.com> Date: Wed, 13 Feb 2019 14:09:54 +0600 Subject: [PATCH] improve sync --- CHANGELOG.md | 3 +++ lightpick.js | 25 ++++++++++++++++++++----- package.json | 2 +- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ff50b5..9fa7c44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Changelog All notable changes to this project will be documented in this file. +[1.2.11] - 2019-02-13 +* Improve sync values with fields + [1.2.10] - 2019-02-12 * fixed bug #36 diff --git a/lightpick.js b/lightpick.js index 803f769..0fff0be 100644 --- a/lightpick.js +++ b/lightpick.js @@ -752,7 +752,7 @@ } } - this.syncFields(); + self.syncFields(); if (!self.isShowing) { self.show(); @@ -902,12 +902,27 @@ syncFields: function() { - if (moment(this._opts.field.value, this._opts.format).isValid()) { - this._opts.startDate = moment(this._opts.field.value, this._opts.format); + if (this._opts.singleDate || this._opts.secondField) { + if (moment(this._opts.field.value, this._opts.format).isValid()) { + this._opts.startDate = moment(this._opts.field.value, this._opts.format); + } + + if (this._opts.secondField && moment(this._opts.secondField.value, this._opts.format).isValid()) { + this._opts.endDate = moment(this._opts.secondField.value, this._opts.format); + } } + else { + var dates = this._opts.field.value.split(this._opts.separator); + + if (dates.length === 2) { + if (moment(dates[0], this._opts.format).isValid()) { + this._opts.startDate = moment(dates[0], this._opts.format); + } - if (this._opts.secondField && moment(this._opts.secondField.value, this._opts.format).isValid()) { - this._opts.endDate = moment(this._opts.secondField.value, this._opts.format); + if (moment(dates[1], this._opts.format).isValid()) { + this._opts.endDate = moment(dates[1], this._opts.format); + } + } } }, diff --git a/package.json b/package.json index a95aab5..daa9274 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lightpick", - "version": "1.2.10", + "version": "1.2.11", "description": "Javascript date range picker - lightweight, no jQuery", "main": "lightpick.js", "scripts": {