-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initializing a datepicker with an input's value #2387
Comments
Hi. I think I fixed this in the commit I just made, can you verify? |
It works fine when I have a date like 4/21/2021. But if I have a date set that is in a format it does not expect, like 21/4/2021, it will give an error in the console about an incorrect date (totally fine), but the control is now broken, and it will not show no matter what I click/focus on. When you look into fixing this, can you ensure that even if a date is invalid (unexpected format), it's value is left intact as the |
Date parsing is done from javascripts native date object. I'll make sure that the control still works in the case and doesn't change the input vlaue. |
Hmm seemed to work for me. Can you fork the v6 stackblitz and let me know if you can reproduce it? |
For sure, I simply forked yours, and added a |
Well I feel dumb. lol. I swear I tried this locally and it worked. :( I try to fix it sorry and thanks. |
Haha, no worries, I know that feeling when things like that happen :-D |
I've got a few others issues I've found while trying to adapt an existing site using TD5, to the new v6 as well. Can't seem to get custom formatting to apply at all (tried both the |
I'm currently trying to get this in to an existing angular project of mine as well. Dinner "real world" testing. I know it's tedious but could you create an issue for each unrelated item? A single stackblitz will do just fine. I really appreciate you try this out and reporting bugs. |
Done, and no worries! Having a compatible datetime picker is the last roadblock I have before I can look at migrating a project that is currently using Bootstrap4, to instead use Bootstrap5. I started doing the testing/migrating once I saw you had an alpha up, so I'm glad that me finding issues helps you track them down :-) |
Hi can you please check out the latest release? I think I've resolved this. |
Still gives an error on some invalid dates. I've updated the stackblitz to |
Hehe, no worries. I chuckled at the commit message when I went looking to update the reference to TD in the stackblitz, and found it was simply "oops :(". :-P |
Hello. Please try your config with this stackblitz. I think I FINALLY for REAL fixed this. |
Almost! No more error at any rate. It still silently shifts invalid dates like I noticed this and mentioned it in one of the other issues but I think what I was getting at, is that there should be different behavior between user entered data, and data in the To me, information supplied by the user should be more aggressively validated. If the date is in an invalid format ( If it's assumedly from the server (since it's the input's To be fair, I'm not entirely sure if my concerns around this are within the scope of the TD control, or should be for the consumer of the TD package (myself in this case) to deal with, but I don't think there's a way to tell where the input being parsed came from currently, so I don't know how a consumer of the package could have different logic in these two scenarios. |
Unfortunately that is the nature of js's date parsing. Moment had a "strict" option but that seems like we're going down the path of a full dt lib. The parse hooks I added ought to allow for people to use moment or dayjs or w/e to determine what is valid or provide more complex parsing. I could potentially look at the input attribute instead of I know removing moment mean relaying on the native functions but that still seems better compared to a direct dependency. |
Oh, I didn't realize that. Yeah, I just tried it in a console window in chrome, and sure enough, if I do As for the other part, just brainstorming here for some way to distinguish between initializing the control versus parsing user input. Perhaps something passed to the |
I added the context to both of those functions. You should be able to get the input or the validation methods or anything the picker provides including the widget itself from there. hooks: {
inputParse: (context: TempusDominus, value: any) => DateTime;
inputFormat: (context: TempusDominus, date: DateTime) => string;
}; |
If the input element for a datepicker has a
value
attribute, the picker should default to that date when opening the picker, but that doesn't seem to be the case from my testingThe text was updated successfully, but these errors were encountered: