SolidOS / solid-ui

User Interface widgets and utilities for Solid
https://solidos.github.io/solid-ui/dist/solid-ui.js
MIT License
148 stars 41 forks source link

DateTimeField Does not seem to initialize from existing value #451

Open timbl opened 2 years ago

timbl commented 2 years ago

According to solid-ui/Documentation/form-examples/demo.html at any rate. image

timbl commented 2 years ago

This one is not obvious. The input field.value get set to the string in the data, but then when read back, field.value is "" .

josephguillaume commented 2 years ago

It seems the problem is that a datetime-local input field only accepts Local date and time strings, i.e. without the Z at the end.

In Chrome a warning is thrown here: https://github.com/solid/solid-ui/blob/c4ad302f361cc4a1de24941a475cb66333c43805/src/widgets/forms/basic.ts#L155

The specified value "2021-10-12T12:34:23Z" does not conform to the required format. The format is "yyyy-MM-ddThh:mm" followed by optional ":ss" or ":ss.SSS".

To get the example to work (https://solid.github.io/solid-ui/Documentation/form-examples/demo.html), it is sufficient to delete the Z.

The solution to this bug is not obvious. As a starting point, we could change the validation pattern to require the Z to be missing https://github.com/solid/solid-ui/blob/c4ad302f361cc4a1de24941a475cb66333c43805/src/widgets/forms/fieldParams.ts#L47

However, this leaves support for xsd:dateTime incomplete. (Admittedly other timezone offsets weren't supported yet either) One option is to implement a renderer for ui:DateTimeField that can handle cases with and without timezone, either with a custom datetime picker or with a second selector to choose the time zone. Another option is to define multiple ui variants, e.g. ui:DateTimeFieldWithTimeZone and ui:DateTimeFieldLocal, with the latter specifically mapped to a datetime-local input field.