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

"modelValue" on validator returns value "true" instead of null/empty moment #248

Open CesarD opened 6 years ago

CesarD commented 6 years ago

I have my control with a validator directive, and in the validator code:

ctrl.$validators.validator1 = function (modelValue, viewValue) { ...... }

When I delete the date from the input, modelValue returns the boolean true, instead of a null value or empty object.

Is this supposed to happen? Any workaround to avoid it? Thanks.

TiagoBrenck commented 6 years ago

@CesarD I had the same problem that you described, and my workaround was a directive that treats the bug. Here is what the directive looks like:

 .directive("undefinedDate", () => {
   return {
      restrict: 'A',
      required: 'ngModel',
      link: (scope, element,attr, ngModel) => {
         const inputModelCtrl =element.controller("ngModel");
         inputModelCtrl.$parsers.push(value => {
            if (value === true || value == "") {
               return undefined;
            }
            return value;
         })
      }
   }
});

And the input: <input undefined-date ng-model="$ctrl.myDateModel" moment-picker="$ctrl.myDateModel" format="MM/DD/YYYY">

I hope this helps you.

CesarD commented 6 years ago

Yes, that's the same I ended up doing. It's just a workaround, but not for avoiding it but for patching it up... Would be useful to know if there's anything to do to prevent it from start or if it can be fixed at all from the library.

easyest commented 5 years ago

Any update on this bug?

CesarD commented 5 years ago

I don't think this will ever get fixed... Most likely project is abandoned. Probably best to take the jump onto Angular 7+