question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Date field cannot be typed in

See original GitHub issue

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:

            scope.$watch('rawValue', function(newValue) {
                scope.value = field.parse()(newValue);
            });

            scope.$watch('value', (newValue, oldValue) => {
                if (newValue === oldValue) {
                    return;
                }

                if (!newValue) {
                    scope.rawValue = null;
                    return;
                }

                scope.rawValue = scope.value instanceof Date ? scope.value : new Date(scope.value);
            });

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' sees foo. This is not a date object, so parse leaves it unchanged, and value is set to foo.
  • $watch('value' sees foo and attempts to construct a new Date object using it. This ends up setting rawValue to an Invalid Date object.
  • $watch('rawValue' sees Invalid Date. This is a date object, so parse tries to manipulate it, but fails and ends up setting the value to null.
  • $watch('value' sees null and correspondingly sets rawValue to null
  • $watch('rawValue' sees null and correspondingly sets value to null
  • $watch('value' sees null, 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).

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
Phoceacommented, Mar 7, 2017

@matheo, if your patch fix both issues, can you create a PR for it please ?

0reactions
jamespsterlingcommented, Mar 20, 2017

Also when you use the datepicker and then click into another field, the date changes ‘magically’.

ng-admin-datepicker-strangeness

Read more comments on GitHub >

github_iconTop Results From Across the Web

Type into date field did not work - UiPath Community Forum
Try “30/03/2018"+"[k(tab)]” in the type into activity and make sure simulate type is unchecked.
Read more >
Why can't I type into datepicker textbox? - Stack Overflow
I tweaked little bit how datetime picker works. It is triggered on change of select. But now I cannot type into the text...
Read more >
Solved: Date picker: Typing in the date (date format mm.dd...
Solved: Hi, I'm building a Power App with the Power App app in Teams and have a problem with the date picker. Property...
Read more >
Date cannot by typed into date field in Chrome in Windows 10
I have a date field (Date of Birth). I can use the date picker to select a date of birth. But I cannot...
Read more >
<input type="date"> - HTML: HyperText Markup Language
By default, <input type="date"> doesn't validate the entered value beyond its format. The interfaces generally don't let you enter anything that ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found