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

Commit

Permalink
feat(datepicker): support HTML5 month input type
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisirhc committed Apr 16, 2015
1 parent 71e840b commit 8a05268
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/datepicker/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,8 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
datepickerPopup: 'yyyy-MM-dd',
html5Types: {
date: 'yyyy-MM-dd',
'datetime-local': 'yyyy-MM-ddTHH:mm:ss.sss'
// TODO: Add other formats/type support
'datetime-local': 'yyyy-MM-ddTHH:mm:ss.sss',
'month': 'yyyy-MM'
},
currentText: 'Today',
clearText: 'Clear',
Expand Down Expand Up @@ -523,6 +523,13 @@ function ($compile, $parse, $document, $position, dateFilter, dateParser, datepi

// datepicker element
var datepickerEl = angular.element(popupEl.children()[0]);
if (isHtml5DateInput) {
if (attrs.type == 'month') {
datepickerEl.attr('datepicker-mode', '"month"');
datepickerEl.attr('min-mode', 'month');
}
}

if ( attrs.datepickerOptions ) {
var options = scope.$parent.$eval(attrs.datepickerOptions);
if(options.initDate) {
Expand Down
19 changes: 19 additions & 0 deletions src/datepicker/test/datepicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1462,6 +1462,25 @@ describe('datepicker directive', function () {
expect(selectedElementIndex()).toEqual( 10 );
});

it('works as month', function() {
setupInputWithType('month');
expect(inputEl.val()).toBe('2010-09');

changeInputValueTo(inputEl, '1980-03');

expect($rootScope.date.getFullYear()).toEqual(1980);
expect($rootScope.date.getMonth()).toEqual(2);
expect($rootScope.date.getDate()).toEqual(30);

expect(getOptions()).toEqual([
['January', 'February', 'March'],
['April', 'May', 'June'],
['July', 'August', 'September'],
['October', 'November', 'December']
]);
expect(selectedElementIndex()).toEqual( 2 );
});

function setupInputWithType(type) {
var wrapElement = $compile('<div><input type="' +
type + '" ng-model="date" datepicker-popup><div>')($rootScope);
Expand Down

0 comments on commit 8a05268

Please sign in to comment.