keystone-classic
keystone-classic copied to clipboard
Field type 'Datetime' - format customization missing
There is no working way to specify the format of Datetime. Also the placeholder is hardcoded in DatetimeField.js
<FormInput name={this.props.paths.time} value={this.state.timeValue} placeholder="HH:MM:SS am/pm" onChange={this.timeChanged} autoComplete="off" />
http://keystonejs.com/docs/database/#fieldtypes-datetime
You can format your Datetime field when adding it to your model:
year: { type: Types.Datetime, format: 'YYYY' }
should work, for example.
Formatting works perfectly fine, but should definitely affect the placeholder!
The input format of the DateTime field is hardcoded, no? https://github.com/keystonejs/keystone/blob/master/fields/types/datetime/DatetimeField.js#L14-L15
Shouldn't this.parseFormatString = this.formatString
, or just validate against the formatString? Otherwise you'd also need to set parseFormat. DateTime validation should function the same as Date, seems to be handled differently.
https://github.com/keystonejs/keystone/blob/master/fields/types/datetime/DatetimeType.js#L20 https://github.com/keystonejs/keystone/blob/master/fields/types/date/DateType.js#L76
It's also hardcoded incorrectly in v3.x. This is a critical issue for me, and an easy fix. https://github.com/keystonejs/keystone/blob/v0.3.x/fields/types/datetime/DatetimeType.js#L86
@jstockwin
year: { type: Types.Datetime, format: 'YYYY' }
- doesn't work, renders 2 fields, date and time
@asliwinski I question using DateTime for a year value. I would likely store this as a number field, as this is the information you are most interested in representing.
The problem with storing it as a DateTime is that you make it timezone-specific, which a simple year value does not want.
If you want to use a richer field, Date is also better for this.
If anyone wants to make a PR so format affects the placeholder, that would be grand.
when i use Types.Datetime , it showing below error
Error: Invalid value for schema path date.type
in unavailability
.
I'm working on a PR for the first part of this issue (lack of control over the format in the admin UI)
It looks like the issue stems from the format property being used to read from and save to the database but being ignored completely by the admin UI field.
As part of the solution I'm trying now I'm splitting the format into timeFormat and dateFormat. Apart from checking the Datetime type itself and updating the docs, is there anything else I should be aware of when changing/introducing new properties to a type?