angular-daterangepicker icon indicating copy to clipboard operation
angular-daterangepicker copied to clipboard

Giving error isValid undefined

Open BMK91 opened this issue 6 years ago • 8 comments

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.

test Bower

"jquery": "2.1.1", "angular": "1.7.2", "moment": "^2.24.0", "bootstrap-daterangepicker": "^3.0.3" "angular-daterangepicker": "^0.3.0"

BMK91 avatar Feb 05 '19 04:02 BMK91

Others issues are still there regarding this version. Like clearable not working

BMK91 avatar Feb 05 '19 05:02 BMK91

I agree, @BMK91. I'm seeing both issues, as well.

cgatesman avatar Mar 04 '19 21:03 cgatesman

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.

phazei avatar Mar 18 '19 18:03 phazei

Getting the first issue here as well. Updated moment.js accordingly but in vain. Please suggest any ideas to try.

aakashaggarwal avatar May 02 '19 12:05 aakashaggarwal

Are you setting your startDate/endDate as moment objects? If it's a moment object then isValid is a method of the moment object...

phazei avatar May 14 '19 01:05 phazei

I solve it by change the normal javascript new Date function when setting startDate,endDate values by moment() thanks to @phazei.

elhuseyni avatar Jul 14 '19 18:07 elhuseyni

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.

Chengrongrong avatar Aug 27 '19 06:08 Chengrongrong

This fix worked for me

https://github.com/fragaria/angular-daterangepicker/compare/master...midhun1993:patch-1

midhun1993 avatar Sep 21 '20 20:09 midhun1993