Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Giving error isValid undefined #306

Open
BMK91 opened this issue Feb 5, 2019 · 8 comments
Open

Giving error isValid undefined #306

BMK91 opened this issue Feb 5, 2019 · 8 comments

Comments

@BMK91
Copy link

BMK91 commented Feb 5, 2019

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
Copy link
Author

BMK91 commented Feb 5, 2019

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

@cgatesman
Copy link

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

@phazei
Copy link
Contributor

phazei commented Mar 18, 2019

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.

@aakashaggarwal
Copy link

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

@phazei
Copy link
Contributor

phazei commented May 14, 2019

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

@elhuseyni
Copy link

elhuseyni commented Jul 14, 2019

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

@Chengrongrong
Copy link

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.

@midhun1993
Copy link

This fix worked for me

master...midhun1993:patch-1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants