From ffef8a341f82c6034b41d7b52b7cfc0dac4df0ef Mon Sep 17 00:00:00 2001 From: Winston Chang Date: Fri, 16 Sep 2016 22:21:29 -0500 Subject: [PATCH] Add workaround for bootstrap datepicker bug with setStartDate and setEndDate --- srcjs/input_binding_date.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/srcjs/input_binding_date.js b/srcjs/input_binding_date.js index d68907b54..4eed9907e 100644 --- a/srcjs/input_binding_date.js +++ b/srcjs/input_binding_date.js @@ -137,8 +137,15 @@ $.extend(dateInputBinding, { } else { date = this._newDate(date); - if (!isNaN(date)) + if (!isNaN(date)) { + // Workaround for https://github.com/eternicode/bootstrap-datepicker/issues/2010 + // If the start date when there's a two-digit year format, it will set + // the date value to null. So we'll save the value, set the start + // date, and the restore the value. + var curValue = $(el).bootstrapDP('getUTCDate'); $(el).bootstrapDP('setStartDate', date); + $(el).bootstrapDP('setUTCDate', curValue); + } } }, // Given an unambiguous date string or a Date object, set the max (end) date @@ -151,8 +158,12 @@ $.extend(dateInputBinding, { } else { date = this._newDate(date); - if (!isNaN(date)) + if (!isNaN(date)) { + // Workaround for same issue as in _setMin. + var curValue = $(el).bootstrapDP('getUTCDate'); $(el).bootstrapDP('setEndDate', date); + $(el).bootstrapDP('setUTCDate', curValue); + } } }, // Given a date string of format yyyy-mm-dd, return a Date object with