Skip to content

Commit d05667e

Browse files
committed
Small cleanup
1 parent 2981ac2 commit d05667e

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

coffee/angular-daterangepicker.coffee

+5-9
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,7 @@ picker.directive 'dateRangePicker', ($compile, $timeout, $parse, dateRangePicker
7373

7474
# Formatter should return just the string value of the input
7575
# It is used for comparison of if we should re-render
76-
modelCtrl.$formatters.push (val) ->
77-
if val and val.startDate
78-
then _format(val)
79-
else ''
76+
modelCtrl.$formatters.push _format
8077

8178
# Render should update the date picker start/end dates as necessary
8279
# It should also set the input element's val with $viewValue as we don't let the rangepicker do this
@@ -85,9 +82,8 @@ picker.directive 'dateRangePicker', ($compile, $timeout, $parse, dateRangePicker
8582
if modelCtrl.$modelValue and modelCtrl.$modelValue.startDate
8683
_setStartDate(modelCtrl.$modelValue.startDate)
8784
_setEndDate(modelCtrl.$modelValue.endDate)
88-
else
89-
_clear()
90-
# Update the input
85+
else _clear()
86+
# Update the input with the $viewValue (generated from $formatters)
9187
el.val(modelCtrl.$viewValue)
9288

9389
# This should parse the string input into an updated model object
@@ -109,7 +105,7 @@ picker.directive 'dateRangePicker', ($compile, $timeout, $parse, dateRangePicker
109105

110106
modelCtrl.$isEmpty = (val) ->
111107
# modelCtrl is empty if val is empty string
112-
not val and val.length > 0
108+
not (angular.isString(val) and val.length > 0)
113109

114110
# _init has to be called anytime we make changes to the date picker options
115111
_init = ->
@@ -142,7 +138,7 @@ picker.directive 'dateRangePicker', ($compile, $timeout, $parse, dateRangePicker
142138
_initBoundaryField = (field, validator, modelField, optName) ->
143139
if attrs[field]
144140
modelCtrl.$validators[field] = (value) ->
145-
validator(opts[optName], value[modelField])
141+
value and validator(opts[optName], value[modelField])
146142
$scope.$watch field, (date) ->
147143
opts[optName] = if date then moment(date) else false
148144
_init()

0 commit comments

Comments
 (0)