Deselect date
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?
@venticco @Belir can you help with that?
Yikes, this is pretty old and unanswered. But this would be very helpful.
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;
}
}