-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Timestamp treated as invalid model value in datepicker #2345
Comments
@oliversalzburg Can you provide a plunker with your issue? |
@bekos Yeah, sorry for not providing one earlier. I just modified the demo plunkr: http://plnkr.co/edit/yDcTUvs7H1xkqJ7XWPBq?p=preview Please note the paragraph indicating "There is an error in your form.". If I set
|
This was bugging us in my training class... I used a Date.now() to generate a time, which Angular can process with a {{ myDate | date:'MM/dd/yyyy' }} template. It was a good exercise for our students to solve, but am curious if this is this on deck for a fix soon? I switched to doing new Date() instead which worked for now but it would be nice to be able to handle a timetick version of the date like Angular's filter does. |
+1 |
I ran into a similar snag with angular + UI-bootstrap to both initialize and style the content of datepicker input at the same time on load in the controller. Long story short:
Noting that
ISO string is apparently what datetime binds to the $modelValue of the form. Interestingly, when using |
+1 |
2 similar comments
+1 |
+1 |
Hi @oliversalzburg - is this with both Angular 1.2.x and 1.3.x? |
@karianna I haven't tested this since I reported it. We just moved to a different approach. 1.3 wasn't released when I reported it, but I don't see why the behavior would have changed. |
I've added the following line on top of if (angular.isNumber(viewValue)) {
viewValue = new Date(viewValue);
} Then it goes through the if/else chain and falls into } else if (angular.isDate(viewValue) && !isNaN(viewValue)) { which handles it correctly. Updated Plunker As an alternative we can have this check on if/else chain itself but I didn't want to repeat that part of the chain again. @karianna Please let me know if you're ok with this, so I'll do a pull request for it. |
Yes please (and updated/new test as well please). |
Accept a number of milliseconds since 01.01.1970 as a valid value for `ng-model` Closes angular-ui#2345
Accept a number of milliseconds since 01.01.1970 as a valid value for `ng-model`: - change parseDate() to handle timestamp values - add the test to `datepicker.spec.js` Closes angular-ui#2345
I also ran into this today and patched mine similarly. I'd also like to be able to write the value back as a timestamp rather than a date object. I'd like to see a timestamp mode that treats the model as a number bidirectionally. |
@danieljsinclair Create a directive with the same name as module.directive('datepickerPopup', function () {
function link(scope, element, attrs, ngModel) {
// View -> Model
ngModel.$parsers.push(function (value) {
return Date.parse(value);
});
}
return {
restrict: 'A',
require: 'ngModel',
link: link
};
}) |
That is a very solid solution / workaround. This email was sent from my iPhone and therefore subject to typos and other inaccuracies.
|
Interesting. I didn't think of creating a directive with a matching name. I wrote a similar buddy-directive earlier, but this relies on the datepicker dateParser accepting a timestamp;
|
This should now be fixed in master. |
Cool! Thanks for taking care of this 👍 |
Accept a number of milliseconds since 01.01.1970 as a valid value for `ng-model`: - change parseDate() to handle timestamp values - add the test to `datepicker.spec.js` Closes angular-ui#2345
Can anyone help as it is still not working for me. I'm on the last 0.14.3 release "1990-08-01T00:00:00" datetime field is not handled correctly in validator func and returns undefined so on validation form fails angular.IsNumber and angular.IsDate obv return false when trying to parse this timestamp. Any ideas? |
@f1ght4fun, without any further information it's nearly impossible to provide any assistance. My first thought is that you're trying to use a string instead of a That said, questions like this are best served by posting them to StackOverflow as documented here. Posting to already closed issues is a good way for stuff to get missed. |
The datepicker directive says ng-model can be "a number of milliseconds since 01.01.1970". However
parseData
will not treat such an input as valid.The text was updated successfully, but these errors were encountered: