Skip to content

Commit 438df4b

Browse files
committed
Merge pull request #60 from benjamin-albert/master
Makes changing the SelectedMonth option update the AltField.
2 parents 696fc77 + 68d4de8 commit 438df4b

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

demo/MonthPicker.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "jquery-ui-month-picker",
33
"description": "jQuery UI Month Picker Plugin",
4-
"version": "3.0.2",
4+
"version": "3.0.3",
55
"license": "GPL-3.0",
66
"repository": "https://github.com/KidSysco/jquery-ui-month-picker.git",
77
"scripts": {

src/MonthPicker.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
The jQuery UI Month Picker Version 3.0.2
2+
The jQuery UI Month Picker Version 3.0.3
33
https://github.com/KidSysco/jquery-ui-month-picker/
44
55
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>

src/MonthPicker.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
The jQuery UI Month Picker Version 3.0.2
2+
The jQuery UI Month Picker Version 3.0.3
33
https://github.com/KidSysco/jquery-ui-month-picker/
44
55
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
@@ -166,7 +166,7 @@ along with this program. If not, see
166166
}
167167

168168
$.MonthPicker = {
169-
VERSION: '3.0.1', // Added in version 2.4;
169+
VERSION: '3.0.3', // Added in version 2.4;
170170
i18n: {
171171
year: 'Year',
172172
prevYear: 'Previous Year',
@@ -528,7 +528,7 @@ along with this program. If not, see
528528

529529
Clear: function () {
530530
this.element.val('');
531-
this._updateAlt(0, '');
531+
$(this.options.AltField).val('');
532532
this._validationMessage.hide();
533533
},
534534

@@ -648,10 +648,14 @@ along with this program. If not, see
648648
_setSelectedMonth: function (_selMonth) {
649649
var month = _encodeMonth(this, _selMonth), _el = this.element;
650650

651-
if (!month) {
652-
_el.val( '' );
651+
if (month) {
652+
var date = new Date( _toYear(month), month % 12, 1 );
653+
_el.val( this._formatMonth( date ) );
654+
655+
this._updateAlt(0, date);
656+
this._validationMessage.hide();
653657
} else {
654-
_el.val( this._formatMonth( new Date( _toYear(month), month % 12, 1)) );
658+
this.Clear();
655659
}
656660

657661
this._ajustYear(this.options);
@@ -840,11 +844,15 @@ along with this program. If not, see
840844
this._titleButton.jqueryUIButton({ label: this._i18n('year') + ' ' + this._pickerYear });
841845
},
842846

847+
// When calling this method with a falsy (undefined) date
848+
// value, this.element.val() is used as the date value.
849+
//
850+
// Therefore it's important to update the input field
851+
// before calling this method.
843852
_updateAlt: function (noop, date) {
844-
// False means use the fields value.
845853
var _field = $(this.options.AltField);
846854
if (_field.length) {
847-
_field.val(this._formatMonth(date, this.options.AltFormat));
855+
_field.val( this._formatMonth(date, this.options.AltFormat) );
848856
}
849857
},
850858

0 commit comments

Comments
 (0)