Skip to content
Snippets Groups Projects
Commit f8938498 authored by MerlinGuillaume's avatar MerlinGuillaume
Browse files

[FIX] web: use dot or comma in date format

The new datepicker doesn't work properly with date formats using dots or
commas

Steps to reproduce:
1. Install Sales
2. Set the language date format to `%m.%d.%Y` and refresh the page
3. Open Sales and trigger the pivot view
4. Add a custom filter on field 'Delivery Date'
5. Click on the date to change it, the format changes
6. Try to enter a date, it is incorrectly parsed

Solution:
Add dot and comma as a possible character for static format

Problem:
Formats using dots were not considered as valid static format so the
value entered was parsed with the format `yyyy/MM/dd` instead

Partial backport of https://github.com/odoo/odoo/commit/5f17d8974652f9606cb57f909c143d15046f1854



opw-3222468

closes odoo/odoo#119235

Signed-off-by: default avatarBruno Boi (boi) <boi@odoo.com>
parent 38198566
Branches
Tags
No related merge requests found
......@@ -36,7 +36,7 @@ const luxonFormatToMomentFormat = (format) => {
*/
const isValidStaticFormat = (format) => {
try {
return /^[\d\s/:-]+$/.test(DateTime.local().toFormat(format));
return /^[\d\s\/.,:-]+$/.test(DateTime.local().toFormat(format));
} catch (_err) {
return false;
}
......
......@@ -509,6 +509,25 @@ QUnit.module("Components", () => {
assert.verifySteps(["datetime-changed"]);
});
QUnit.test("Datepicker works with dots and commas in format", async (assert) => {
assert.expect(2);
const picker = await mountPicker(DateTimePicker, {
props: {
date: DateTime.fromFormat("10/03/2023 13:14:27", "dd/MM/yyyy HH:mm:ss"),
format: "dd.MM,yyyy",
}
});
let input = picker.el.querySelector(".o_datepicker_input");
assert.strictEqual(input.value, "10.03,2023");
await click(input);
assert.strictEqual(input.value, "10.03,2023");
});
QUnit.test('custom filter date', async function (assert) {
assert.expect(3);
class MockedSearchModel extends ActionModel {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment