angular-mighty-datepicker icon indicating copy to clipboard operation
angular-mighty-datepicker copied to clipboard

Deselect date

Open oddlyfunctional opened this issue 10 years ago • 3 comments

There's an optional field in my form which the user may not want to fill in. I've added a button that assigns the model to undefined, but the angular-mighty-datepicker coerces undefined values to the current date using moment.js (https://github.com/monterail/angular-mighty-datepicker/blob/master/src/angular-mighty-datepicker.coffee#L221).

I've managed to avoid that by not using the ngModel option (passing a dummy value, since the directive doesn't work without a ngModel), and using the callback to set the selected value to my model. This works, but the date keeps selected, even though the model is empty, which is misleading for the user.

Is there an appropriate way to deselect the date in angular-mighty-datepicker?

oddlyfunctional avatar Oct 22 '15 14:10 oddlyfunctional

@venticco @Belir can you help with that?

jandudulski avatar Dec 16 '15 16:12 jandudulski

Yikes, this is pretty old and unanswered. But this would be very helpful.

RyanEaves avatar May 13 '16 17:05 RyanEaves

The strangest thing of this library is that when set ng-model to empty string after init, it'll crash the whole thing. I would expect this will be one of the major test !!

For now, I manage to not run into this issue by adding a few lines into model watch, the "return" make sure we don't _prepare the calendar when date is not valid. The originality of the crash is due to options.start got reset based on the current date.

          $scope.$watch('model', function(newVal, oldVal) {
            if (!moment.isMoment(newVal)) {
              newVal = moment(newVal);
              if (!newVal.isValid()) {
                $scope.model = newVal;
                return;
              }
            }

windmaomao avatar Aug 07 '17 13:08 windmaomao