Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

DatePicker - manually editing date to an invalid date then back to valid date not working. #3736

Closed
marc-hughes opened this issue May 31, 2015 · 12 comments

Comments

@marc-hughes
Copy link

Steps to reproduce:

Scenario 1:
http://plnkr.co/edit/vDeypZk4Gq7odCTGRIMf?p=preview

  1. Place cursor at end of input
  2. Type the number 2
    Expected/Actual: This is an invalid date, the "Value" underneath goes blank
  3. Delete the number 2
    Expected: This is now a valid date again, the "Value" underneath should be displayed
    Actual: The value stays blank

Scenario 2:
http://plnkr.co/edit/vDeypZk4Gq7odCTGRIMf?p=preview

  1. Place cursor before the first digit in the date
  2. Press delete twice to delete the month
    Expected/Actual: This is an invalid date, the "Value" underneath goes blank
  3. Enter 03 to set the month again
    Expected: This is now a valid date again, the "Value" underneath should be displayed
    Actual: It stays blank

I see these results in both Chrome and Firefox latest.

In Chrome Only: In scenario 2 if you type 3 instead of 03, everything works as expected.

@marc-hughes
Copy link
Author

I believe this is also causing a more common type of error. If you completely clear the date and then type 2014-05-05
it will not work correctly. I'm assuming because 2014-05-0 is an invalid date, and then you type the last "5" and hit the bug.

@rvanbaalen
Copy link
Contributor

At the moment Datepicker as quite a lot open issues. We're currently planning a large refactor on that particular module of UI Bootstrap but don't hold your breath.

@marc-hughes
Copy link
Author

I would suggest that the datepicker is marked deprecated in the documentation so people don't start using it in production environments.

@rvanbaalen
Copy link
Contributor

It's not deprecated, it's just not actively developed at the moment.

@marc-hughes
Copy link
Author

Perhaps deprecated was the wrong word. A notice exactly like your comment would probably help set the right expectations so people don't feel burnt.

At the moment Datepicker has quite a lot open issues. 
We're currently planning a large refactor on that particular 
module of UI Bootstrap but don't hold your breath.

@rvanbaalen
Copy link
Contributor

Good one. I'll discuss it with the other maintainers right away.

@trishrempel
Copy link

Glad I found this thread, I've had tons of headaches getting the validation working properly.

@davidcox66
Copy link

I have a solution for this one. I had a format of yyyy/MM/dd. Doing any edit that made this momentarily invalid would create an invalid date object. The date picker would use this invalid date that it assigned to the model (variable named 'baseDate') as the starting point for creating a new date. Except many of the fields are NaN. By checking for this condition before using the date as a baseline, the problem is avoided. I just added a isNaN(baseDate) at the appropriate place. Here is the git diff.

diff --git a/ui-bootstrap-tpls-0.13.0.js b/ui-bootstrap-tpls-0.13.0.js
index 6119661..dac366f 100644
--- a/ui-bootstrap-tpls-0.13.0.js
+++ b/ui-bootstrap-tpls-0.13.0.js
@@ -781,7 +781,7 @@ angular.module('ui.bootstrap.dateparser', [])
 
     if ( results && results.length ) {
       var fields, dt;
-      if (baseDate) {
+      if (baseDate && !isNaN(baseDate) ) {
         fields = {
           year: baseDate.getFullYear(),
           month: baseDate.getMonth(),

@ovarunendra
Copy link

+1

@kildareflare
Copy link

+1 Nice work @davidcox66, any chance of raising a pull request?
It would be great to get this into the next release.

@wesleycho wesleycho modified the milestones: 0.13.1 (npm), 0.13.2 (Performance) Jul 23, 2015
@bouzuya
Copy link

bouzuya commented Jul 27, 2015

👍

@pakoangl
Copy link

pakoangl commented May 2, 2018

  createMoment: function (m) {
    if (tz) {
      return moment.tz(m, tz);
    } else {
      //If input is a moment, and we have no TZ info, we need to remove TZ
      //info from the moment, otherwise the newly created moment will take
      //the timezone of the input moment. The easiest way to do that is to
      //take the unix timestamp, and use that to create a new moment.
      //The new moment will use the local timezone of the user machine.
        return moment.isMoment(m) ? moment.unix(m.unix()) : (m != undefined && m.length == 10 ? moment(m, 'DD/MM/YYYY') : moment(m));
    }
  },

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

No branches or pull requests

9 participants