How to add type: date for react-jsonschema-form

Viewed 4505

Using this library: https://github.com/mozilla-services/react-jsonschema-form I want to add a date selector field and here in the documentation is says:

date: By default, an input[type=date] element is used;
date-time: By default, an input[type=datetime-local] element is used.

and they posted this picture, I want mine to look the same as the date one:

enter image description here

I use last version of Chrome, for the compatibility issue.

I've try to write something like this:

date: {
       type: "date",
       title: "Date"
        }

but I got this error:

Unsupported field schema for field root_date: Unknown field type date.

Check this fiddle:

https://jsfiddle.net/bogdanul11/69z2wepo/91003/

1 Answers

You should define the json shema as following:

"datetime": { // whatever name you want
  "type": "string", //Attention!
  "format": "date-time"
},

instead of what you did:

date: {
  "type": "date",
  "title": "Date"
}

The react-jsonschema-form library provides really nice playground: https://mozilla-services.github.io/react-jsonschema-form/

Related