Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
Fixes #1433
Browse files Browse the repository at this point in the history
Changed events from on blur to on change.

Changed the events in the test to be change instead of blur because of the new listener that has been setup.
  • Loading branch information
BenjaminNeilDavis committed Aug 5, 2015
1 parent 20695a9 commit 1603c0f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 deletions.
26 changes: 10 additions & 16 deletions js/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,11 @@

this.$calendar.find('.datepicker-today').on('click.fu.datepicker', $.proxy(this.todayClicked, this));
this.$days.on('click.fu.datepicker', 'tr td button', $.proxy(this.dateClicked, this));
this.$element.find('.dropdown-menu').on('mousedown.fu.datepicker', $.proxy(this.dropdownMousedown, this));
this.$header.find('.next').on('click.fu.datepicker', $.proxy(this.next, this));
this.$header.find('.prev').on('click.fu.datepicker', $.proxy(this.prev, this));
this.$headerTitle.on('click.fu.datepicker', $.proxy(this.titleClicked, this));
this.$input.on('blur.fu.datepicker', $.proxy(this.inputBlurred, this));
this.$input.on('focus.fu.datepicker', $.proxy(this.inputFocused, this));
this.$input.on('change.fu.datepicker', $.proxy(this.inputChanged, this));
this.$input.on('mousedown.fu.datepicker', $.proxy(this.showDropdown, this));
this.$wheels.find('.datepicker-wheels-back').on('click.fu.datepicker', $.proxy(this.backClicked, this));
this.$wheels.find('.datepicker-wheels-select').on('click.fu.datepicker', $.proxy(this.selectClicked, this));
this.$wheelsMonth.on('click.fu.datepicker', 'ul button', $.proxy(this.monthClicked, this));
Expand Down Expand Up @@ -187,6 +186,7 @@
this.selectedDate = date;
this.$input.val(this.formatDate(date));
this.inputValue = this.$input.val();
this.hideDropdown();
this.$input.focus();
this.$element.trigger('dateClicked.fu.datepicker', date);
},
Expand All @@ -209,14 +209,6 @@
this.$element.find('.input-group-btn').removeClass('open');
},

dropdownMousedown: function () {
var self = this;
this.preventBlurHide = true;
setTimeout(function () {
self.preventBlurHide = false;
}, 0);
},

enable: function () {
this.$element.removeClass('disabled');
this.$element.find('input, button').removeAttr('disabled');
Expand Down Expand Up @@ -263,7 +255,7 @@
return this.restricted;
},

inputBlurred: function (e) {
inputChanged: function () {
var inputVal = this.$input.val();
var date;
if (inputVal !== this.inputValue) {
Expand All @@ -277,14 +269,16 @@
}

}
},

if (!this.preventBlurHide) {
this.$element.find('.input-group-btn').removeClass('open');
showDropdown: function (e) {
if (!this.$input.is(':focus')){
this.$element.find('.input-group-btn').addClass('open');
}
},

inputFocused: function (e) {
this.$element.find('.input-group-btn').addClass('open');
hideDropdown: function () {
this.$element.find('.input-group-btn').removeClass('open');
},

isInvalidDate: function (date) {
Expand Down
8 changes: 4 additions & 4 deletions test/datepicker-moment-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ define(function(require){
});

$datepickerInput.val('03/31/1987');
$datepickerInput.trigger('blur');
$datepickerInput.trigger('change');

equal(called, 1, 'Event was triggered as expected');
equal(typeof event, 'object', 'Appropriate event object passed back as argument');
Expand Down Expand Up @@ -175,7 +175,7 @@ define(function(require){
equal($datepicker.find('.datepicker-wheels-year').hasClass('hidden'), true, 'years wheel hidden');

$datepickerInput.val('03/31/1988');
$datepickerInput.trigger('blur');
$datepickerInput.trigger('change');
dateString = $datepicker.datepicker('getDate').toString();
equal((dateString==='Invalid Date' || dateString==='NaN'), true, 'user can\t input date outside current year');
});
Expand Down Expand Up @@ -349,7 +349,7 @@ define(function(require){
var formatted;

$datepickerInput.val(dateString);
$datepickerInput.trigger('blur');
$datepickerInput.trigger('change');
formatted = $datepicker.datepicker('getFormattedDate');

equal( formatted, dateString, 'moment.js formatted date should be equal to input');
Expand Down Expand Up @@ -384,7 +384,7 @@ define(function(require){
equal($datepicker.datepicker('getFormattedDate'), date, 'moment.js parsed date correctly after initialization with de culture');

$input.val('aa.bb.cccc');
$input.trigger('blur');
$input.trigger('change');
dateString = $datepicker.datepicker('getDate').toString();
equal((dateString==='Invalid Date' || dateString==='NaN'), true, 'datepicker should return \'Invalid Date\' or \'NaN\' when bad data is entered');
});
Expand Down
4 changes: 2 additions & 2 deletions test/datepicker-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ define(function(require){
});

$datepickerInput.val('03/31/1987');
$datepickerInput.trigger('blur');
$datepickerInput.trigger('change');

equal(called, 1, 'Event was triggered as expected');
equal(typeof event, 'object', 'Appropriate event object passed back as argument');
Expand Down Expand Up @@ -191,7 +191,7 @@ define(function(require){
equal($datepicker.find('.datepicker-wheels-year').hasClass('hidden'), true, 'years wheel hidden');

$datepickerInput.val('03/31/1988');
$datepickerInput.trigger('blur');
$datepickerInput.trigger('change');
dateString = $datepicker.datepicker('getDate').toString();
equal((dateString==='Invalid Date' || dateString==='NaN'), true, 'user can\t input date outside current year');
});
Expand Down

0 comments on commit 1603c0f

Please sign in to comment.