Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using lodash not able to validate selected date

I try to validate selected date from angularjs weather date is selected or not. So for this i use lodash.isEmpty it returns empty but the date is selected.

 else if(lodash.isEmpty(exchangeRate.validTo)){
        console.log(exchangeRate.validTo);
        $scope.errorvalidTo = 'invalid'
    }

i have selected date but it always says empty

like image 583
Abhishek Kumar Avatar asked Oct 15 '25 03:10

Abhishek Kumar


1 Answers

Well, _.isEmpty(new Date()) will always return true, because Object.keys(new Date()).length === 0. If you look at the source code of the isEmpty func : you can see this:

      ...
      for (var key in value) {
        if (hasOwnProperty.call(value, key)) {
         return false;
        }
      }
     return true;

A Date object has no key/values so it'll return true.

use !_.isDate(...) could be a better idea

like image 77
Corentin PRUNE Avatar answered Oct 18 '25 08:10

Corentin PRUNE



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!