indrimuska / angular-moment-picker

Angular Moment Picker is an AngularJS directive for date and time picker using Moment.js.
http://indrimuska.github.io/angular-moment-picker/
MIT License
525 stars 226 forks source link

maxView is overwritten by format #170

Open AgDude opened 7 years ago

AgDude commented 7 years ago

When a "max-view" is explicitly defined as an attribute, it should always be respected. If the format does not display the max view, the auto-detected max-view is being used.

"hour" is requested, but "month" is returned, because the input only shows the date, the time is displayed elsewhere. In this case the "format" is set using the provider and the max view is set on the element.

See this plunker for example: https://plnkr.co/edit/dq5VDpqGBje2DVIEij3G?p=preview

AgDude commented 7 years ago

I want to say thanks for all of the updates in the past few months, especially as they relate to #60.

I looks like this issue is a little deeper that I thought, there are quite a few places that still rely on formatting the moment model, and using the string (viewValue) for comparison or operation. The next place I see where this is an issue is in this watcher:

$scope.$watch(() => momentToValue($ctrl.$modelValue, $scope.format), (newViewValue, oldViewValue)

This is where checkValue is called, but will not execute if the format doesn't include the changed part of the moment, and in some cases is overwriting the model. The case where the overwrite happens is for example I have a format that shows date only, and change the time and date, the time may be lost (this seems like it may depend on the order watchers execute in.

indrimuska commented 7 years ago

Hi @AgDude, thanks for the kind words. Actually, this behavior is by design, so when using min/max view properties, they will be overridden by the smart view auto-detection if the format selected does not require a specific view (i.e. format HH:mm doesn't require decade, year, month, and minute views).