keystone-classic icon indicating copy to clipboard operation
keystone-classic copied to clipboard

Field type 'Datetime' - format customization missing

Open chiss2906 opened this issue 8 years ago • 8 comments

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" />

chiss2906 avatar Jul 14 '16 14:07 chiss2906

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.

jstockwin avatar Jul 14 '16 16:07 jstockwin

Formatting works perfectly fine, but should definitely affect the placeholder!

mxstbr avatar Jul 14 '16 17:07 mxstbr

The input format of the DateTime field is hardcoded, no? https://github.com/keystonejs/keystone/blob/master/fields/types/datetime/DatetimeField.js#L14-L15

wmertens avatar Jul 14 '16 20:07 wmertens

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

jonathan-l-rivera avatar Nov 03 '16 17:11 jonathan-l-rivera

@jstockwin year: { type: Types.Datetime, format: 'YYYY' } - doesn't work, renders 2 fields, date and time

asliwinski avatar Jul 03 '17 19:07 asliwinski

@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.

Noviny avatar Oct 04 '17 13:10 Noviny

when i use Types.Datetime , it showing below error Error: Invalid value for schema path date.type in unavailability.

hari419 avatar Dec 07 '17 09:12 hari419

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?

gsteinert avatar Dec 29 '17 18:12 gsteinert