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

Commit

Permalink
fix(datepicker): throw error if inside md-input-container. For #5055
Browse files Browse the repository at this point in the history
  • Loading branch information
jelbourn committed Nov 4, 2015
1 parent 06c60af commit 5004a2a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/components/datepicker/datePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
'</md-calendar>' +
'</div>' +
'</div>',
require: ['ngModel', 'mdDatepicker'],
require: ['ngModel', 'mdDatepicker', '?^mdInputContainer'],
scope: {
minDate: '=mdMinDate',
maxDate: '=mdMaxDate',
Expand All @@ -92,6 +92,11 @@
var ngModelCtrl = controllers[0];
var mdDatePickerCtrl = controllers[1];

var mdInputContainer = controllers[2];
if (mdInputContainer) {
throw Error('md-datepicker should not be placed inside md-input-container.');
}

mdDatePickerCtrl.configureNgModel(ngModelCtrl);
}
};
Expand Down
18 changes: 17 additions & 1 deletion src/components/datepicker/datePicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ describe('md-date-picker', function() {
'ng-disabled="isDisabled">' +
'</md-datepicker>';

beforeEach(module('material.components.datepicker', 'ngAnimateMock'));
var fakeInputModule = angular.module('fakeInputModule', [])
.directive('mdInputContainer', function() {
return {controller: angular.noop};
});

beforeEach(module('material.components.datepicker', 'ngAnimateMock', 'fakeInputModule'));

beforeEach(inject(function($rootScope, $injector) {
$compile = $injector.get('$compile');
Expand Down Expand Up @@ -94,6 +99,17 @@ describe('md-date-picker', function() {
expect(controller.inputElement.placeholder).toBe('Fancy new placeholder');
});

it('should throw an error when inside of md-input-container', function() {
var template =
'<md-input-container>' +
'<md-datepicker ng-model="myDate"></md-datepicker>' +
'</md-input-container>';

expect(function() {
$compile(template)(pageScope);
}).toThrowError('md-datepicker should not be placed inside md-input-container.');
});

describe('ngMessages suport', function() {
it('should set the `required` $error flag', function() {
pageScope.isRequired = true;
Expand Down

0 comments on commit 5004a2a

Please sign in to comment.