angular-daterangepicker
angular-daterangepicker copied to clipboard
Giving error isValid undefined
Hi,
When setting pre-date values with min, max it gives error
angular.js:15018 TypeError: a.startDate.isValid is not a function at f.$validators.invalid (angular-daterangepicker.js:266)
vm.dateRange = {
"startDate": moment().toDate(),
"endDate" : moment().toDate()
};
vm.minDate = moment().subtract(2, "d").toDate();
vm.maxDate = moment().add(2, "d").toDate();
Here is the screenshot of console debug.
Bower
"jquery": "2.1.1", "angular": "1.7.2", "moment": "^2.24.0", "bootstrap-daterangepicker": "^3.0.3" "angular-daterangepicker": "^0.3.0"
Others issues are still there regarding this version. Like clearable not working
I agree, @BMK91. I'm seeing both issues, as well.
I use this version (0.3.0) with a dynamic minDate and maxDate.
As with all dates in this picker, everything needs to be set with a moment object. As I can see from your screenshot, value.startDate
exists. If value.startDate.isValid
doesn't exist, perhaps you're on an older moment version? https://momentjs.com/docs/#/parsing/is-valid/
Also, AFAIK, 'clearable' works just fine. There's a working example of it in example.html
so if it's not working for you, again, more info would be needed, and for that a new ticket.
Edit: actually, from your code snippet, you're converting your moment objects to a regular js date objects. Why are you using "toDate()" ? Don't do that and it should work.
Getting the first issue here as well. Updated moment.js accordingly but in vain. Please suggest any ideas to try.
Are you setting your startDate/endDate as moment objects? If it's a moment object then isValid is a method of the moment object...
I solve it by change the normal javascript new Date
function when setting startDate,endDate values by moment()
thanks to @phazei.
Remark: My English is a little weak, please don't mind.
I solved the problem and rewrite it. The parameter brings 「options.singleDatePicker」 equal true. I using javascript 「typeof」 function, if the value is 'object', using moment isValid function, otherwise use directly the value.
angular-daterangepicker.js code 263 if (opts.singleDatePicker) { check = value && value.isValid(); } content to if (opts.singleDatePicker) { if(typeof(value) == 'object'){ value = moment(value) check = value && value.isValid(); }else{ check = value; } }
The above is my method.
This fix worked for me
https://github.com/fragaria/angular-daterangepicker/compare/master...midhun1993:patch-1