This repository has been archived by the owner on May 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Added ability to handle empty model in timepicker #4203
Closed
+37
−13
Closed
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8cd457b
Added ability to handle empty model
fmccown 6cb0ea6
Added ability to handle empty model - fixed PR
ftorghele-ef d283102
Merge pull request #1 from Eurofunk/master
fmccown 00e6d2e
chore(timepicker): Added ability to handle empty model - fixed tests
ftorghele-ef 311244f
Merge pull request #2 from Eurofunk/master
fmccown File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,6 +143,9 @@ angular.module('ui.bootstrap.timepicker', []) | |
} | ||
|
||
function pad(value) { | ||
if (value === null) { | ||
return ''; | ||
} | ||
return (angular.isDefined(value) && value.toString().length < 2) ? '0' + value : value.toString(); | ||
} | ||
|
||
|
@@ -218,22 +221,28 @@ angular.module('ui.bootstrap.timepicker', []) | |
var hours = getHoursFromTemplate(), | ||
minutes = getMinutesFromTemplate(); | ||
|
||
if (angular.isDefined(hours) && angular.isDefined(minutes)) { | ||
selected.setHours(hours); | ||
if (selected < min || selected > max) { | ||
invalidate(true); | ||
} else { | ||
refresh('h'); | ||
if (angular.isDefined(hours)) { | ||
if (angular.isDefined(minutes)) { | ||
selected.setHours(hours); | ||
selected.setMinutes(minutes); | ||
if (selected < min || selected > max) { | ||
invalidate(true); | ||
} else { | ||
refresh('h'); | ||
} | ||
} | ||
} else { | ||
invalidate(true); | ||
} | ||
}; | ||
|
||
hoursInputEl.bind('blur', function(e) { | ||
if (!$scope.invalidHours && $scope.hours < 10) { | ||
ngModelCtrl.$setTouched(); | ||
if ($scope.hours === null || $scope.hours === "") { | ||
invalidate(true); | ||
} else if (!$scope.invalidHours && $scope.hours < 10) { | ||
$scope.$apply(function() { | ||
$scope.hours = pad($scope.hours); | ||
$scope.hours = pad($scope.hours); | ||
}); | ||
} | ||
}); | ||
|
@@ -242,20 +251,26 @@ angular.module('ui.bootstrap.timepicker', []) | |
var minutes = getMinutesFromTemplate(), | ||
hours = getHoursFromTemplate(); | ||
|
||
if (angular.isDefined(minutes) && angular.isDefined(hours)) { | ||
selected.setMinutes(minutes); | ||
if (selected < min || selected > max) { | ||
invalidate(undefined, true); | ||
} else { | ||
refresh('m'); | ||
if (angular.isDefined(minutes)) { | ||
if (angular.isDefined(hours)) { | ||
selected.setHours(hours); | ||
selected.setMinutes(minutes); | ||
if (selected < min || selected > max) { | ||
invalidate(undefined, true); | ||
} else { | ||
refresh('m'); | ||
} | ||
} | ||
} else { | ||
invalidate(undefined, true); | ||
} | ||
}; | ||
|
||
minutesInputEl.bind('blur', function(e) { | ||
if (!$scope.invalidMinutes && $scope.minutes < 10) { | ||
ngModelCtrl.$setTouched(); | ||
if ($scope.minutes === null) { | ||
invalidate(undefined, true); | ||
} else if (!$scope.invalidMinutes && $scope.minutes < 10) { | ||
$scope.$apply(function() { | ||
$scope.minutes = pad($scope.minutes); | ||
}); | ||
|
@@ -300,17 +315,23 @@ angular.module('ui.bootstrap.timepicker', []) | |
} | ||
|
||
function updateTemplate(keyboardChange) { | ||
var hours = selected.getHours(), minutes = selected.getMinutes(); | ||
|
||
if ($scope.showMeridian) { | ||
hours = (hours === 0 || hours === 12) ? 12 : hours % 12; // Convert 24 to 12 hour system | ||
} | ||
if (ngModelCtrl.$modelValue == null) { | ||
$scope.hours = null; | ||
$scope.minutes = null; | ||
$scope.meridian = meridians[0]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indentation is off here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, seems like the whole block's indentation is off. |
||
} else { | ||
var hours = selected.getHours(), minutes = selected.getMinutes(); | ||
|
||
if ($scope.showMeridian) { | ||
hours = (hours === 0 || hours === 12) ? 12 : hours % 12; // Convert 24 to 12 hour system | ||
} | ||
|
||
$scope.hours = keyboardChange === 'h' ? hours : pad(hours); | ||
if (keyboardChange !== 'm') { | ||
$scope.minutes = pad(minutes); | ||
} | ||
$scope.meridian = selected.getHours() < 12 ? meridians[0] : meridians[1]; | ||
$scope.hours = keyboardChange === 'h' ? hours : pad(hours); | ||
if (keyboardChange !== 'm') { | ||
$scope.minutes = pad(minutes); | ||
} | ||
$scope.meridian = selected.getHours() < 12 ? meridians[0] : meridians[1]; | ||
} | ||
} | ||
|
||
function addMinutes(date, minutes) { | ||
|
@@ -353,8 +374,15 @@ angular.module('ui.bootstrap.timepicker', []) | |
}; | ||
|
||
$scope.toggleMeridian = function() { | ||
var minutes = getMinutesFromTemplate(), | ||
hours = getHoursFromTemplate(); | ||
|
||
if (!$scope.noToggleMeridian()) { | ||
addMinutesToSelected(12 * 60 * (selected.getHours() < 12 ? 1 : -1)); | ||
if (angular.isDefined(minutes) && angular.isDefined(hours)) { | ||
addMinutesToSelected(12 * 60 * (selected.getHours() < 12 ? 1 : -1)); | ||
} else { | ||
$scope.meridian = $scope.meridian == meridians[0] ? meridians[1] : meridians[0]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use |
||
} | ||
} | ||
}; | ||
}]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to
if(!$scope.minutes) {