-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Datepicker clicking clear button on popup gives "ng-model" value must be a Date object #3701
Comments
Reproducable in this plunkr. Doesn't look like desired behaviour indeed. |
Looks like the problem is either in $viewChangeListener or in the dateParser: 'clear' passes an empty string as a selected value and the dateParser parses it to 'Invalid date'. It seems to me, that null should be returned in this case. |
In datepicker.js line 652, I changed the code to this, and it appears to fix the issue. |
This is a very annoying bug indeed. Is there a temporary workaround for this that we can use externally? Thanks! |
Reverted back to 0.12.0 for now. |
I still get this error when I use the format of 'dd/MM/yyyy' when manually typing in the date and starting with a number greater than 12 it wont work. |
I am guessing this is happening because there is no date present on the page when it loads. What I ended up doing was setting the value to undefined instead of null if there is no value for that field. If there is a value then I convert it to a new Date object. I hope this code helps. I believe that the value cannot be null but it can be undefined. In my case I was setting the value as it was returned from the JSON object in my service like this: |
If you have a Datepicker directive as a popup, and choose a valid date, then popup again and click the clear button, you get the following exception:
Datepicker directive: "ng-model" value must be a Date object, a number of milliseconds since 01.01.1970 or a string representing an RFC2822 or ISO 8601 date.
This then leaves the form.$invalid property as true, which is not correct, if this is not a required field.
Open the console window on the demo page, and follow the above 2 steps, and you will see the error emitted to console window.
The text was updated successfully, but these errors were encountered: