From de7f8e23288de9318b0da3fe367c0f0f42d82d4e Mon Sep 17 00:00:00 2001 From: Johannes Raggam Date: Wed, 25 Nov 2026 00:41:26 +0100 Subject: [PATCH 1/5] pat-date-picker: Autoformat. --- src/pat/date-picker/date-picker.js | 7 +- src/pat/date-picker/index.html | 333 +++++++++++++++-------------- 2 files changed, 173 insertions(+), 167 deletions(-) diff --git a/src/pat/date-picker/date-picker.js b/src/pat/date-picker/date-picker.js index 85142b5f6..1a5979d3d 100644 --- a/src/pat/date-picker/date-picker.js +++ b/src/pat/date-picker/date-picker.js @@ -33,7 +33,6 @@ parser.addAlias("behaviour", "behavior"); export const storage = store.session("pat-date-picker"); - export default Base.extend({ name: "date-picker", trigger: ".pat-date-picker", @@ -95,7 +94,7 @@ export default Base.extend({ "pat-date-picker--label", (e) => { e.preventDefault(); - } + }, ); } @@ -195,7 +194,9 @@ export default Base.extend({ i18n = await response.json(); storage.set(this.options.i18n, i18n); } catch { - log.error(`date-picker could not load i18n for ${this.options.i18n}`); + log.error( + `date-picker could not load i18n for ${this.options.i18n}`, + ); } } if (i18n) { diff --git a/src/pat/date-picker/index.html b/src/pat/date-picker/index.html index cbe0d809a..d442b8899 100644 --- a/src/pat/date-picker/index.html +++ b/src/pat/date-picker/index.html @@ -1,11 +1,13 @@ - - pat-date-picker demo page - - - - - - -
-
- -
- -
- -
- -
- - -
- - -
- -
- - -
- - - -
- - -
- - - -
- - - -
- -
- -
- -
-
- -
- +
+ + + - -
- + + + From e0ea9dc14336ba42779bbe9b6fb98bceda4228d8 Mon Sep 17 00:00:00 2001 From: Johannes Raggam Date: Wed, 25 Nov 2026 01:02:26 +0100 Subject: [PATCH 2/5] pat-datetime-picker: Autoformat. --- .../datetime-picker/datetime-picker.test.js | 26 +++---- src/pat/datetime-picker/documentation.md | 7 +- src/pat/datetime-picker/index.html | 74 +++++++++---------- 3 files changed, 51 insertions(+), 56 deletions(-) diff --git a/src/pat/datetime-picker/datetime-picker.test.js b/src/pat/datetime-picker/datetime-picker.test.js index 30590db0a..04789ab5d 100644 --- a/src/pat/datetime-picker/datetime-picker.test.js +++ b/src/pat/datetime-picker/datetime-picker.test.js @@ -30,24 +30,24 @@ describe("pat-datetime-picker", function () { expect( document.querySelector( - '.pika-lendar .pika-select-year option[selected="selected"]' - ).textContent + '.pika-lendar .pika-select-year option[selected="selected"]', + ).textContent, ).toBe(year); expect( document.querySelector( - '.pika-lendar .pika-select-month option[selected="selected"]' - ).value + '.pika-lendar .pika-select-month option[selected="selected"]', + ).value, ).toBe(month); expect( document .querySelector(".pika-lendar td.is-today button") - .getAttribute("data-pika-day") + .getAttribute("data-pika-day"), ).toBe(day); expect( - document.querySelector(".pika-lendar th:first-child abbr").textContent + document.querySelector(".pika-lendar th:first-child abbr").textContent, ).toBe("Sun"); }); @@ -66,7 +66,7 @@ describe("pat-datetime-picker", function () { document.querySelector("input[type=text]").click(); expect( - document.querySelector(".pika-lendar th:first-child abbr").textContent + document.querySelector(".pika-lendar th:first-child abbr").textContent, ).toBe("Mon"); }); @@ -86,20 +86,20 @@ describe("pat-datetime-picker", function () { expect( document.querySelector( - '.pika-lendar .pika-select-year option[selected="selected"]' - ).textContent + '.pika-lendar .pika-select-year option[selected="selected"]', + ).textContent, ).toBe("1900"); expect( document.querySelector( - '.pika-lendar .pika-select-month option[selected="selected"]' - ).value + '.pika-lendar .pika-select-month option[selected="selected"]', + ).value, ).toBe("0"); expect( document .querySelector(".pika-lendar td.is-selected button") - .getAttribute("data-pika-day") + .getAttribute("data-pika-day"), ).toBe("1"); }); @@ -118,7 +118,7 @@ describe("pat-datetime-picker", function () { document.querySelector("input[type=text]").click(); expect(document.querySelectorAll(".pika-lendar .pika-week")[0].textContent).toBe( - "35" + "35", ); }); diff --git a/src/pat/datetime-picker/documentation.md b/src/pat/datetime-picker/documentation.md index 359309ee8..e534ac8c6 100644 --- a/src/pat/datetime-picker/documentation.md +++ b/src/pat/datetime-picker/documentation.md @@ -9,7 +9,7 @@ for browsers which don't yet support the HTML5 date input. ### Examples -#### Enforcing the styled non-HTML5 picker universally. +#### Enforcing the styled non-HTML5 picker universally By default this pattern will NOT defer to the browser's HTML5 picker. @@ -19,11 +19,11 @@ By default this pattern will NOT defer to the browser's HTML5 picker. -#### Specifying the "min" and "max" attributes. +#### Specifying the "min" and "max" attributes -#### Show the week number. +#### Show the week number @@ -44,7 +44,6 @@ Here are all the i18n values in JSON format: "weekdaysShort": ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"] } - ### Option reference The HTML5 attributes `min` and `max` will be honoured. diff --git a/src/pat/datetime-picker/index.html b/src/pat/datetime-picker/index.html index e59b6bfbe..83120eb1b 100644 --- a/src/pat/datetime-picker/index.html +++ b/src/pat/datetime-picker/index.html @@ -1,43 +1,39 @@ - - pat-datetime-picker demo page - - - - - - -
-
-
-
-
-
-
- + + + + + +
+
+
+
+
+
+
+ From 35ced92b70ad0bf54f4b466754c5dbd4a330acf7 Mon Sep 17 00:00:00 2001 From: Johannes Raggam Date: Mon, 10 Jul 2023 18:31:19 +0200 Subject: [PATCH 3/5] feat(pat-date-picker): Introduce new behavior mode "editable". With `behavior: editable`, the pattern changes the `type="date"` field to `type="text"` when it initializes. Users can type a date in `YYYY-MM-DD` format or choose one from the JavaScript calendar. Set `i18n` to the URL of a JSON file to translate the calendar. The browser treats typed values as plain text for constraint validation. --- src/pat/date-picker/date-picker.js | 7 +++-- src/pat/date-picker/date-picker.test.js | 40 +++++++++++++++++++++++++ src/pat/date-picker/documentation.md | 28 ++++++++++++----- src/pat/date-picker/index.html | 7 +++++ 4 files changed, 72 insertions(+), 10 deletions(-) diff --git a/src/pat/date-picker/date-picker.js b/src/pat/date-picker/date-picker.js index 1a5979d3d..6dfbbb471 100644 --- a/src/pat/date-picker/date-picker.js +++ b/src/pat/date-picker/date-picker.js @@ -11,7 +11,7 @@ import utils from "../../core/utils"; const log = logging.getLogger("date-picker"); export const parser = new Parser("date-picker"); -parser.addArgument("behavior", "styled", ["native", "styled"]); +parser.addArgument("behavior", "styled", ["native", "styled", "editable"]); parser.addArgument("week-numbers", [], ["show", "hide"]); parser.addArgument("i18n"); // URL pointing to JSON resource with i18n values parser.addArgument("first-day", 0); @@ -149,7 +149,10 @@ export default Base.extend({ } } else if (disabled) { return; - } else if (utils.checkInputSupport("date", "invalid date")) { + } else if ( + this.options.behavior !== "editable" && + utils.checkInputSupport("date", "invalid date") + ) { // behavior native with native support. return; } else if (el.getAttribute("type") === "date") { diff --git a/src/pat/date-picker/date-picker.test.js b/src/pat/date-picker/date-picker.test.js index 0b5d51997..d8a100d2d 100644 --- a/src/pat/date-picker/date-picker.test.js +++ b/src/pat/date-picker/date-picker.test.js @@ -577,6 +577,46 @@ describe("pat-date-picker", function () { expect(el.value).toBe(isodate); }); + it("opens a localized picker on an editable field even with native date input support", async () => { + jest.spyOn(utils, "checkInputSupport").mockReturnValue(true); + document.body.innerHTML = ` +
+ +
+ `; + const response = await mock_fetch_i18n(); + storage.set("/keyboard-i18n.json", await response.json()); + const el = document.querySelector("input"); + const instance = new pattern(el); + + try { + await events.await_pattern_init(instance); + + expect(el.type).toBe("text"); + expect(el.value).toBe("2021-10-21"); + expect(el.style.display).not.toBe("none"); + expect(document.querySelector("time")).toBeNull(); + + el.click(); + const calendar = document.querySelector(".pika-single:not(.is-hidden)"); + const month = calendar.querySelector(".pika-select-month option:checked"); + expect(month.textContent).toBe("Oktober"); + + const day = calendar.querySelector('button[data-pika-day="22"]'); + day.dispatchEvent(new Event("mousedown", { bubbles: true })); + expect(new FormData(el.form).get("date")).toBe("2021-10-22"); + } finally { + instance.pikaday?.destroy(); + storage.remove("/keyboard-i18n.json"); + } + }); + it("12 - does not initialize the date picker in styled behavior when disabled", async () => { document.body.innerHTML = ` -#### Enforcing the styled non-HTML5 picker universally. +#### Choosing a date with the styled picker -By default this pattern will NOT defer to the browser's HTML5 picker. +The default `styled` behavior displays the date in a `