Similar Topics...
 |
DateRangePicker (DanGrossman) does not support two digit years The DateRangePicker (by Dan Grossman/improvely) does not support two digit years entered into the box such as '1/1/14'. There are two workarounds posted: One, change your format to MM/DD/YY. But then the control doesn't accept 1/1/2014 any more. Two, set min date to 2014. But then '1/1/15' is incorrectly rendered as '1/1/2014'. Here is a full correction that will treat any two digit year as being in the millennia 2000. This could easily be adapted for a cutoff year or to pull the current millennia. Note: for a date range, the picker also requires a space before and after the hyphen. This is also fixed below. 1. Add helper function to daterangepicker.js DateRangePicker.prototype (around line 446): parseDateString: function(elementValue) { if (this.locale.format == 'MM/DD/YYYY') { var elementValueParts = elementValue.split('/'); if (elementValueParts.length == 3) { if (elementValueParts[2] < 100) { elementValueParts[2] = 2000 + Number(elementValueParts[2]); elementValue = elementValueParts[0] + '/' + elementValueParts[1] + '/' + elementValueParts[2]; } } } return elementValue; } 2. Call this function to parse the value of the input in the existing controlChanged function. var dateString = this.element.val().split(this.locale.separator), start = null, end = null; // handle lack of whitespace before/after hyphen if (dateString.length == 1 && this.element.val().indexOf('-')) { dateString = this.element.val().replace("-", " - ").split(this.locale.separator); } if (dateString.length === 2) { start = moment( this.parseDateString(dateString[0]) , this.locale.format).utcOffset(this.timeZone); end = moment( this.parseDateString(dateString[1]) , this.locale.format).utcOffset(this.timeZone); } if (this.singleDatePicker || start === null || end === null) { start = moment( this.parseDateString (this.element.val()), this.locale.format).utcOffset(this.timeZone); end = start; }
Created By: amos 7/29/2015 12:10:27 PM Updated: 7/29/2015 12:22:59 PM
|
|
|
|
|
|