Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Adds a test that ensures the menu is not closed after clicking the
input field again.
  • Loading branch information
benjamin-albert committed Oct 24, 2015
commit 73811d679a5c440e44de3de88b6252fee6a000c0
28 changes: 14 additions & 14 deletions MonthPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,11 +371,6 @@ http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt.
},

Open: function (event) {
// If there is an open menu close it first.
if (_openedInstance) {
_openedInstance.Close(event);
}

if (!this.options.Disabled && !this._visible) {
var _elem = this.element, _opts = this.options;

Expand All @@ -384,20 +379,25 @@ http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt.
if (_opts.OnBeforeMenuOpen.call(_elem[0], event) === false || event.isDefaultPrevented()) {
return false;
}

this._visible = true;
this._ajustYear(_opts);

_openedInstance = this;
var _menu = this._monthPickerMenu;
this._showMonths();

// If there is an open menu close it first.
if (_openedInstance) {
_openedInstance.Close(event);
}

_openedInstance = this;
var _menu = this._monthPickerMenu;
this._showMonths();

$(document).on('click' + _eventsNs + this.uuid, $.proxy(this.Close, this))
$(document).on('click' + _eventsNs + this.uuid, $.proxy(this.Close, this))
.on('keydown' + _eventsNs + this.uuid, $.proxy(this._keyDown, this));

// Trun off validation so that clicking one of the months
// won't blur the input field and trogger vlaidation
// befroe the month was chosen (click event was triggered).
// Trun off validation so that clicking one of the months
// won't blur the input field and trogger vlaidation
// befroe the month was chosen (click event was triggered).
// It is turned back on when Hide() is called.
_elem.off('blur' + _eventsNs).focus();

Expand Down
10 changes: 10 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,11 +530,21 @@ QUnit.test('Disable button', function( assert ) {
// Don't leave the menu open (not really necessary).
$(NoButtonField).MonthPicker('Enable');

// Fails the test if the menu was closed after clicking the input field again.
$(NoButtonField).MonthPicker({
OnBeforeMenuClose: function() {
assert.notOk(true, "The menu shouldn't closed after clicking the input field again.");
}
});

// Make sure that clicking the input field still opens the menu.
$(NoButtonField).trigger('click');
assert.ok($(MonthPicker_NoButtonField).is(':visible'), 'Clicking the input field still openes the correct menu.');

$(NoButtonField).trigger('click');

// Don't leave the menu open (not really necessary).
$(NoButtonField).MonthPicker('ClearAllCallbacks');
$(NoButtonField).MonthPicker('Close');
});

Expand Down