From 15ac2b6062a88248f42f6599050fc8861fdd2542 Mon Sep 17 00:00:00 2001 From: wasinger Date: Wed, 5 Jun 2013 13:44:22 +0200 Subject: [PATCH 1/2] Set selectedMonth and selectedYear from the value attribute of the input element if it is not empty --- jquery.mtz.monthpicker.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/jquery.mtz.monthpicker.js b/jquery.mtz.monthpicker.js index d37f9bd..7097428 100755 --- a/jquery.mtz.monthpicker.js +++ b/jquery.mtz.monthpicker.js @@ -89,6 +89,40 @@ }); } + // get selectedMonth and selectedYear from value attribute + if ($this.val() != '') { + var pattern = settings.pattern.replace('mmm', 'xxx'); // TODO: setting by month name not supported yet + pattern = pattern.replace('mm', '(\\d{2})'); + pattern = pattern.replace('m', '(\\d{1,2})'); + pattern = pattern.replace('yyyy', '(\\d{4})'); + pattern = pattern.replace('yy', '(\\d{2})'); + var regexp = new RegExp(pattern); + var matches = regexp.exec($this.val()); + if (matches.length > 2) { + var month, year1; + if (settings.pattern.indexOf('y') > settings.pattern.indexOf('m')) { + month = matches[1]; + year1 = matches[2]; + } else { + month = matches[2]; + year1 = matches[1]; + } + month = parseInt(month.replace(/^0/, '')); + year1 = parseInt(year1); + if (year1 < 50) { + year1 += 2000; + } else if (year1 < 100) { + year1 += 1900; + } + if (year1 >= settings.startYear && year1 <= settings.finalYear) { + settings.selectedYear = year1; + } + if (month >= 1 && month <= 12) { + settings.selectedMonth = month; + } + } + } + $this.monthpicker('mountWidget', settings); $this.bind('monthpicker-click-month', function (e, month, year) { From 76434b860c98780bac72a45eb94c112a6b4e416e Mon Sep 17 00:00:00 2001 From: Christoph Singer Date: Tue, 2 Jul 2013 13:03:19 +0200 Subject: [PATCH 2/2] corrected parsing integer value from string with leading 0 --- jquery.mtz.monthpicker.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jquery.mtz.monthpicker.js b/jquery.mtz.monthpicker.js index 7097428..c42a960 100755 --- a/jquery.mtz.monthpicker.js +++ b/jquery.mtz.monthpicker.js @@ -107,8 +107,8 @@ month = matches[2]; year1 = matches[1]; } - month = parseInt(month.replace(/^0/, '')); - year1 = parseInt(year1); + month = parseInt(month, 10); + year1 = parseInt(year1, 10); if (year1 < 50) { year1 += 2000; } else if (year1 < 100) {