feat(12.2-02): add the datepicker field with server-side bounds and date list columns
- type: datepicker compiles the D-20 keys; format maps to displayFormat with WinterCMS's momentFormat table - boot fails when the mode does not match the column's Go type (time.Time, lagoon.Date, lagoon.TimeOfDay) - datepicker is a writable scalar field; minDate and maxDate are rechecked on save - columns.yaml accepts type: date and type: time; Scanner/Valuer structs are columns, not relations - conformance fixture carries date and datetime fields; README, forms and lists docs
This commit is contained in:
@@ -92,8 +92,9 @@ for _, f := range form.Fields {
|
||||
| `widget` | A plugin custom element with a server action; see [Partials and widgets](partials-and-widgets.md). |
|
||||
| `partial` | A server-rendered template; see [Partials and widgets](partials-and-widgets.md). |
|
||||
| `fileupload` | Uploads for an attachOne or attachMany relation; see [File uploads](#file-uploads). |
|
||||
| `datepicker` | A date, date and time, or time of day; see [Date pickers](#date-pickers). |
|
||||
|
||||
The WinterCMS widgets that are not in this list (the rich editor, the media finder, the repeater and the others) are not provided. A field with one of those types stops the start-up.
|
||||
The WinterCMS widgets that are not in this list (the rich editor, the markdown editor, the code editor, the color picker, the media finder, the repeater, the tag list and the others) are not provided. A field with one of those types stops the start-up.
|
||||
|
||||
### Field options
|
||||
|
||||
@@ -101,6 +102,48 @@ A field takes `label`, `comment`, `type`, `required`, `default`, `tab`, `span` (
|
||||
|
||||
`context: update` shows a field only on the update form, and `context: create` only on the create form; a list of contexts is also accepted. The context is enforced on the server too: a field that is hidden on a form is never written by that form's save, whatever the request body holds.
|
||||
|
||||
## Date pickers
|
||||
|
||||
A `type: datepicker` field edits one model column. Its `mode` decides the column's Go type, and the start-up stops when they do not match:
|
||||
|
||||
| `mode` | Go type of the column | JSON value |
|
||||
|--------|------------------------|------------|
|
||||
| `datetime` (the default) | `time.Time` or `*time.Time` (a `timestamptz` column) | `"2026-10-02T10:30:00Z"` |
|
||||
| `date` | `lagoon.Date` or `*lagoon.Date` (a `DATE` column) | `"2026-10-02"` |
|
||||
| `time` | `lagoon.TimeOfDay` or `*lagoon.TimeOfDay` (a `TIME` column) | `"14:30:00"` |
|
||||
|
||||
A plugin does not define its own date types; see [Casts and validation](../database/casts-and-validation.md) for the two framework types. Use the pointer types for an optional value: an empty picker stores NULL, and `required: true` refuses it.
|
||||
|
||||
```yaml
|
||||
fields:
|
||||
published_on:
|
||||
label: acme.blog::lang.posts.published_on
|
||||
type: datepicker
|
||||
mode: date
|
||||
minDate: 2000-01-01
|
||||
starts_at:
|
||||
label: acme.blog::lang.posts.starts_at
|
||||
type: datepicker
|
||||
format: d.m.Y H:i
|
||||
firstDay: 1
|
||||
```
|
||||
|
||||
The field takes the generic keys plus these WinterCMS keys:
|
||||
|
||||
| Key | Meaning |
|
||||
|-----|---------|
|
||||
| `mode` | `date`, `datetime` or `time`. |
|
||||
| `format` | The display format as a PHP `date()` format. It is turned into the SPA's format at boot (the schema serves it as `displayFormat`); a letter with no equivalent, such as `T`, `U` or `c`, stops the start-up. It changes only how the value is shown, not the order of the editable segments, which follows the admin's locale. |
|
||||
| `minDate`, `maxDate` | The earliest and latest calendar date (`YYYY-MM-DD`). Not valid on `mode: time`. |
|
||||
| `yearRange` | Years either side of today (`10`) or a `[from, to]` list for the year selector. |
|
||||
| `firstDay` | The first day of the week, 0 (Sunday) to 6. |
|
||||
| `twelveHour` | Shows a 12-hour clock. |
|
||||
| `ignoreTimezone` | `mode: datetime` only: the value is shown and saved as entered, with no time zone conversion. |
|
||||
|
||||
`options`, `emptyOption`, `nameFrom` and every other key stop the start-up.
|
||||
|
||||
`minDate` and `maxDate` are checked again on save: a value whose calendar date (the UTC date of a datetime, or its wall-clock date with `ignoreTimezone`) lies outside them is a 422 on the field. A `datetime` value is stored in UTC and the admin SPA shows and edits it in the browser's time zone; `date` and `time` values are never converted.
|
||||
|
||||
## File uploads
|
||||
|
||||
A `type: fileupload` field edits one attachment relation of the form's model. The model declares its relations with an `AttachRelations` method (`attach.HasRelations`) and implements `attach.Owner`; see [Attachments](../database/attachments.md). The field name must be one of the declared relation names, otherwise the start-up stops.
|
||||
|
||||
Reference in New Issue
Block a user