[iOS] Fix cannot change local storage range date

The date's value was being set on every redraw, and since we handle date
selection onfocusout on iOS, this would result in date having an
outdated value if a redraw (triggered by progress monitor for example)
happens between input and focusout events.

To mitigate this, we only set the date's value `oncreate`.

Close #9642

Co-authored-by: hrb-hub <hrb-hub@users.noreply.github.com>
This commit is contained in:
bir 2025-10-07 11:09:06 +02:00 committed by hrb-hub
parent 3838a9e2c4
commit 7e1a5584bf

View file

@ -289,15 +289,22 @@ export class DatePicker implements Component<DatePickerAttrs> {
private renderMobileDateInput({ date, onDateSelected, disabled }: DatePickerAttrs): Children {
return m("input.fill-absolute.z1", {
disabled: disabled,
type: "date",
type: TextFieldType.Date,
style: {
opacity: 0,
// This overrides platform-specific width setting, we want to cover the whole field
minWidth: "100%",
minHeight: "100%",
},
// Format as ISO date format (YYYY-MM-dd). We use luxon for that because JS Date only supports full format with time.
value: date != null ? DateTime.fromJSDate(date).toISODate() : "",
oncreate: (vnode) => {
// We set the date's value oncreate only. Otherwise, the value would be set on every redraw, and since
// we handle date selection onfocusout on iOS, this would result in date having an outdated value if
// a redraw happens between input and focusout events.
// Format as ISO date format (YYYY-MM-dd). We use luxon for that because JS Date only supports full format with time.
const vnodeDom = vnode.dom as HTMLInputElement
vnodeDom.value = date != null ? (DateTime.fromJSDate(date).toISODate() ?? "") : ""
},
// On iOS we use "onfocusout" instead of "oninput" because the native date picker changes the input immediately, triggering an "oninput" event.
// And tapping "done" has the same effect as tapping outside the picker, it only closes the picker.