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.

localized date incorrectly submitted as part of <form>

See original GitHub issue

I am trying to use duet-date-picker with Thymeleaf (server-side rendering). It works as long as I don’t use the localization support.

I added this in a <script> tag in my page:

    const picker = document.querySelector('duet-date-picker');
    const DATE_FORMAT = /^(\d{1,2})\.(\d{1,2})\.(\d{4})$/;

    if (picker) {
        picker.dateAdapter = {
            parse(value = '', createDate) {
                try {
                    console.log('parsing' + value);
                    const matches = value.match(DATE_FORMAT);

                    if (matches) {
                        return createDate(matches[3], matches[2], matches[1]);
                    }
                } catch (err) {
                    console.log(err);
                }
            },
            format(date) {
                console.log('formatting: ' + date);
                return `${date.getDate()}.${date.getMonth() + 1}.${date.getFullYear()}`;
            },
        };
    }

I see lot’s of formatting... statements, but never parsing... and also no error in the console.

When I check with dev tools, I see updates to the value attribute of <duet-date-picker>, but the value of the actual <input> is not updated. Due to this, my server-side thinks that nothing was selected. For some reason, that does not seem to be an issue when not using the localization support. Am I doing something wrong?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:18 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
wimdeblauwecommented, Nov 27, 2020

I can confirm it works with version 1.1.0. Thanks for the bugfix!

1reaction
WickyNilliamscommented, Oct 29, 2020

Sorry, this fell through the net. I’ll see if i can get a PR together tomorrow

Read more comments on GitHub >

github_iconTop Results From Across the Web

Date formatting - Incorrect Locale - Power Platform Community
Solved: I have a form field, which is autopopulated by the variable 'd1', which is initialized this way: Set(d1,Text( Today(), "[$-en-US]dd ...
Read more >
Wrong date format when submit Spring form - Stack Overflow
My problem is that the date input is in a form, and when I submit the form, it doesn't take the good format....
Read more >
<input type="datetime-local"> - HTML - MDN Web Docs
The problem is with the client side of things: parsing of dates with more than 4 digits in the year. <!--midnight of January...
Read more >
Date and time localization - Lokalise Blog
Date time localization is done different ways in different languages. Let's see how to do it in five popular programming languages.
Read more >
Demystifying DateTime Manipulation in JavaScript - Toptal
You can then format it to extract only the date part as follows: ... "7/22/2016, 04:21 AM", Display localized date and time based...
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