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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With