Skip to content

Commit

Permalink
timePicker - Change by input
Browse files Browse the repository at this point in the history
Problem with timePicker not updating the model correctly when just using
the timePicker on its own
  • Loading branch information
Gillardo committed Mar 13, 2015
1 parent 763c266 commit 3f097bf
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 21 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bootstrap-ui-datetime-picker",
"version": "1.0.7",
"version": "1.0.8",
"homepage": "https://github.com/Gillardo/bootstrap-ui-datetime-picker",
"authors": [
"Gillardo <[email protected]>"
Expand Down
24 changes: 17 additions & 7 deletions datetime-picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
scope.showButtonBar = angular.isDefined(attrs.showButtonBar) ? scope.$parent.$eval(attrs.showButtonBar) : datepickerPopupConfig.showButtonBar;

// determine which pickers should be available. Defaults to date and time
scope.enableDate = !(scope.enableDate == false);
scope.enableTime = !(scope.enableTime == false);
scope.enableDate = scope.enableDate === false;
scope.enableTime = scope.enableTime === false;

This comment has been minimized.

Copy link
@edmondchui

edmondchui Mar 13, 2015

The change to these two lines makes the datepicker never show up. It should be

                    scope.enableDate = !(scope.enableDate === false);
                    scope.enableTime = !(scope.enableTime === false);

This comment has been minimized.

Copy link
@Gillardo

Gillardo via email Mar 13, 2015

Author Owner

// default picker view
scope.showPicker = scope.enableDate ? 'date' : 'time';
Expand All @@ -50,10 +50,10 @@
// popup element used to display calendar
var popupEl = angular.element('' +
'<div datetime-picker-popup>' +
'<div ng-if="enableDate" collapse="!(showPicker == \'date\')" datepicker></div>' +
'<div collapse="!(showPicker == \'time\')">' +
'<div timepicker style="margin:0 auto"></div>' +
'</div>' +
'<div ng-if="enableDate" collapse="!(showPicker == \'date\')" datepicker></div>' +
'<div collapse="!(showPicker == \'time\')">' +
'<div timepicker style="margin:0 auto"></div>' +
'</div>' +
'</div>');

// get attributes from directive
Expand Down Expand Up @@ -117,6 +117,16 @@
} else if (angular.isString(viewValue)) {
var date = dateParser.parse(viewValue, dateFormat) || new Date(viewValue);

// has problem parsing a time only, so create a date
// with the time added on the end, and a dummy formatter
// and use this to see if the time is valid
if (scope.enableTime && !scope.enableDate) {
var timeFormat = 'EEE MMM dd yyyy ' + dateFormat;
var newTime = 'Fri Mar 12 2015 ' + viewValue;

date = dateParser.parse(newTime, timeFormat) || new Date(newTime);
}

if (isNaN(date)) {
ngModel.$setValidity('date', false);
return undefined;
Expand Down Expand Up @@ -172,7 +182,7 @@

element.bind('input change keyup', function () {
scope.$apply(function () {
scope.date = parseDate(ngModel.$viewValue);
scope.date = ngModel.$modelValue;
});
});

Expand Down
28 changes: 19 additions & 9 deletions dist/datetime-picker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// https://github.com/Gillardo/bootstrap-ui-datetime-picker
// Version: 1.0.7
// Released: 2015-03-12
// Version: 1.0.8
// Released: 2015-03-13
angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bootstrap.position'])
.directive('datetimePicker', ['$compile', '$parse', '$document', '$position', 'dateFilter', 'dateParser', 'datepickerPopupConfig',
function ($compile, $parse, $document, $position, dateFilter, dateParser, datepickerPopupConfig) {
Expand All @@ -27,8 +27,8 @@ angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bo
scope.showButtonBar = angular.isDefined(attrs.showButtonBar) ? scope.$parent.$eval(attrs.showButtonBar) : datepickerPopupConfig.showButtonBar;

// determine which pickers should be available. Defaults to date and time
scope.enableDate = !(scope.enableDate == false);
scope.enableTime = !(scope.enableTime == false);
scope.enableDate = scope.enableDate === false;
scope.enableTime = scope.enableTime === false;

// default picker view
scope.showPicker = scope.enableDate ? 'date' : 'time';
Expand All @@ -53,10 +53,10 @@ angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bo
// popup element used to display calendar
var popupEl = angular.element('' +
'<div datetime-picker-popup>' +
'<div ng-if="enableDate" collapse="!(showPicker == \'date\')" datepicker></div>' +
'<div collapse="!(showPicker == \'time\')">' +
'<div timepicker style="margin:0 auto"></div>' +
'</div>' +
'<div ng-if="enableDate" collapse="!(showPicker == \'date\')" datepicker></div>' +
'<div collapse="!(showPicker == \'time\')">' +
'<div timepicker style="margin:0 auto"></div>' +
'</div>' +
'</div>');

// get attributes from directive
Expand Down Expand Up @@ -120,6 +120,16 @@ angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bo
} else if (angular.isString(viewValue)) {
var date = dateParser.parse(viewValue, dateFormat) || new Date(viewValue);

// has problem parsing a time only, so create a date
// with the time added on the end, and a dummy formatter
// and use this to see if the time is valid
if (scope.enableTime && !scope.enableDate) {
var timeFormat = 'EEE MMM dd yyyy ' + dateFormat;
var newTime = 'Fri Mar 12 2015 ' + viewValue;

date = dateParser.parse(newTime, timeFormat) || new Date(newTime);
}

if (isNaN(date)) {
ngModel.$setValidity('date', false);
return undefined;
Expand Down Expand Up @@ -175,7 +185,7 @@ angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bo

element.bind('input change keyup', function () {
scope.$apply(function () {
scope.date = parseDate(ngModel.$viewValue);
scope.date = ngModel.$modelValue;
});
});

Expand Down
6 changes: 3 additions & 3 deletions dist/datetime-picker.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "bootstrap-ui-datetime-picker",
"url": "https://github.com/Gillardo/bootstrap-ui-datetime-picker",
"version": "1.0.7",
"version": "1.0.8",
"devDependencies": {
"grunt": "^0.4.5",
"grunt-angular-templates": "^0.5.7",
Expand Down

0 comments on commit 3f097bf

Please sign in to comment.