angular-moment-picker icon indicating copy to clipboard operation
angular-moment-picker copied to clipboard

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

Open CesarD opened this issue 7 years ago • 4 comments

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.

CesarD avatar Mar 19 '18 15:03 CesarD

@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.

TiagoBrenck avatar May 28 '18 23:05 TiagoBrenck

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.

CesarD avatar May 29 '18 14:05 CesarD

Any update on this bug?

easyest avatar Apr 17 '19 15:04 easyest

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

CesarD avatar Apr 18 '19 04:04 CesarD