Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit aef8953

Browse files
chrisirhcrvanbaalen
authored and
rvanbaalen
committed
feat(datepicker): support HTML5 month input type
Closes #3499
1 parent 1a9e88f commit aef8953

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/datepicker/datepicker.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,8 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
449449
datepickerPopup: 'yyyy-MM-dd',
450450
html5Types: {
451451
date: 'yyyy-MM-dd',
452-
'datetime-local': 'yyyy-MM-ddTHH:mm:ss.sss'
453-
// TODO: Add other formats/type support
452+
'datetime-local': 'yyyy-MM-ddTHH:mm:ss.sss',
453+
'month': 'yyyy-MM'
454454
},
455455
currentText: 'Today',
456456
clearText: 'Clear',
@@ -526,6 +526,13 @@ function ($compile, $parse, $document, $position, dateFilter, dateParser, datepi
526526

527527
// datepicker element
528528
var datepickerEl = angular.element(popupEl.children()[0]);
529+
if (isHtml5DateInput) {
530+
if (attrs.type == 'month') {
531+
datepickerEl.attr('datepicker-mode', '"month"');
532+
datepickerEl.attr('min-mode', 'month');
533+
}
534+
}
535+
529536
if ( attrs.datepickerOptions ) {
530537
var options = scope.$parent.$eval(attrs.datepickerOptions);
531538
if(options.initDate) {

src/datepicker/test/datepicker.spec.js

+19
Original file line numberDiff line numberDiff line change
@@ -1462,6 +1462,25 @@ describe('datepicker directive', function () {
14621462
expect(selectedElementIndex()).toEqual( 10 );
14631463
});
14641464

1465+
it('works as month', function() {
1466+
setupInputWithType('month');
1467+
expect(inputEl.val()).toBe('2010-09');
1468+
1469+
changeInputValueTo(inputEl, '1980-03');
1470+
1471+
expect($rootScope.date.getFullYear()).toEqual(1980);
1472+
expect($rootScope.date.getMonth()).toEqual(2);
1473+
expect($rootScope.date.getDate()).toEqual(30);
1474+
1475+
expect(getOptions()).toEqual([
1476+
['January', 'February', 'March'],
1477+
['April', 'May', 'June'],
1478+
['July', 'August', 'September'],
1479+
['October', 'November', 'December']
1480+
]);
1481+
expect(selectedElementIndex()).toEqual( 2 );
1482+
});
1483+
14651484
function setupInputWithType(type) {
14661485
var wrapElement = $compile('<div><input type="' +
14671486
type + '" ng-model="date" datepicker-popup><div>')($rootScope);

0 commit comments

Comments
 (0)