Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

fix(datepicker): updateOn not working with non-bubbling events #9632

Merged
merged 1 commit into from
Sep 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 12 additions & 0 deletions src/components/datepicker/js/datepickerDirective.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,18 @@

// Responds to external error state changes (e.g. ng-required based on another input).
ngModelCtrl.$viewChangeListeners.unshift(angular.bind(this, this.updateErrorState));

// Forwards any events from the input to the root element. This is necessary to get `updateOn`
// working for events that don't bubble (e.g. 'blur') since Angular binds the handlers to
// the `<md-datepicker>`.
var updateOn = ngModelCtrl.$options && ngModelCtrl.$options.updateOn;

if (updateOn) {
this.ngInputElement.on(
updateOn,
angular.bind(this.$element, this.$element.triggerHandler, updateOn)
);
}
};

/**
Expand Down
14 changes: 13 additions & 1 deletion src/components/datepicker/js/datepickerDirective.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ describe('md-datepicker', function() {
expect(controller.ngModelCtrl.$touched).toBe(true);
});

it('should become touch from blurring the input', function() {
it('should become touched from blurring the input', function() {
populateInputElement('17/1/2015');

var input = angular.element(controller.inputElement);
Expand All @@ -371,6 +371,18 @@ describe('md-datepicker', function() {
populateInputElement('7');
expect(pageScope.myDate).toEqual(date);
});

it('should work with ngModelOptions.updateOn', function() {
var expectedDate = new Date(2015, JAN, 17);

createDatepickerInstance('<md-datepicker ng-model="myDate" ' +
'ng-model-options="{ updateOn: \'blur\' }"></md-datepicker>');

populateInputElement('01/17/2015');
angular.element(element.querySelector('input')).triggerHandler('blur');

expect(pageScope.myDate).toEqual(expectedDate);
});
});

describe('floating calendar pane', function() {
Expand Down