Closed Joe-Edwards closed 7 years ago
In many use cases, operators want to manage hour and minutes, but it is not enabled now by the degration. These cases are more popular than https://github.com/marmelab/ng-admin/issues/899, so https://github.com/marmelab/ng-admin/pull/1196 should be reverted once.
Please fix this. (T_T)
I patched my DateField to be able to work with the date selector fixing the timezone diff:
scope.rawValue = scope.value instanceof Date ? scope.value : new Date(new Date(scope.value).getTime() + (new Date().getTimezoneOffset() * 60 * 1000));
@matheo, if your patch fix both issues, can you create a PR for it please ?
Yup, the infinite loop is now fixed with my PR #1318.
It will be published soon!
I misunderstood the issue, it's about manually edit the date field. The relation with the PR #1317 was confusing.
I re-open the issue, sorry for the inconvenience !
Also when you use the datepicker and then click into another field, the date changes 'magically'.
If you have a 'date' field, you can no longer type the date in it explicitly. Attempting to modify an existing date also just deletes it.
You can see the behaviour in the ng-admin demo - https://marmelab.com/ng-admin-demo/index.html#/customers/edit/485 - try changing the birthday without opening the picker.
I think this was broken by https://github.com/marmelab/ng-admin/issues/899 - it used to work in an older version of ng-admin.
The problem is because maDateField watches both value and rawValue:
The problem is, if at any point an invalid date string is in the box - suppose the string 'foo'. The following sequence happens:
$watch('rawValue'
seesfoo
. This is not a date object, soparse
leaves it unchanged, andvalue
is set tofoo
.$watch('value'
seesfoo
and attempts to construct a new Date object using it. This ends up settingrawValue
to anInvalid Date
object.$watch('rawValue'
seesInvalid Date
. This is a date object, soparse
tries to manipulate it, but fails and ends up setting the value tonull
.$watch('value'
seesnull
and correspondingly setsrawValue
tonull
$watch('rawValue'
seesnull
and correspondingly setsvalue
tonull
$watch('value'
seesnull
, this is the same as the last value, and the cycle ends!The net result is
null
- which removes the text you tried to write from the box.This is related to https://github.com/marmelab/ng-admin/issues/1271 which will be caused by a similar loop. However in that case, if you are in a timezone, the value/rawValue watches will loop, and because the 'parse' method applies a timezone correction the value never stabilises (resulting in the infinite loop).