diff --git a/README.md b/README.md index 432d7c6d96..586c343fcf 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ render(( Here's a list of supported alternative widgets for different JSONSchema data types: -#### `boolean` +#### `boolean`: * `radio`: a radio button group with `true` and `false` as selectable values; * `select`: a select box with `true` and `false` as options; @@ -103,9 +103,17 @@ Here's a list of supported alternative widgets for different JSONSchema data typ #### `string`: - * `textarea`: a `textarea` element + * `textarea`: a `textarea` element; * by default, a regular `input[type=text]` element is used. +#### `number` and `integer`: + + * `updown`: an `input[type=number]` updown selector; + * `range`: an `input[type=range]` slider; + * by default, a regular `input[type=text]` element is used. + +> Note: for numbers, `min`, `max` and `step` input attributes values will be handled according to JSONSchema's `minimum`, `maximium` and `multipleOf` values when they're defined. + ## Development server ``` diff --git a/fixtures/ErrorList/index.js b/fixtures/ErrorList/index.js deleted file mode 100644 index cf3f8c3b3c..0000000000 --- a/fixtures/ErrorList/index.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - errors: [ - {stack: "error message 1"}, - {stack: "error message 2"}, - ] -}; diff --git a/fixtures/Form/deeply-nested-schema.js b/fixtures/Form/deeply-nested-schema.js deleted file mode 100644 index 66c361342a..0000000000 --- a/fixtures/Form/deeply-nested-schema.js +++ /dev/null @@ -1,27 +0,0 @@ -module.exports = { - schema: { - type: "object", - title: "lvl 1 obj", - properties: { - object: { - type: "object", - title: "lvl 2 obj", - properties: { - array: { - type: "array", - items: { - type: "object", - title: "lvl 3 obj", - properties: { - bool: { - type: "boolean", - default: true - } - } - } - } - } - } - } - } -}; diff --git a/fixtures/Form/nested-default.js b/fixtures/Form/nested-default.js deleted file mode 100644 index eca767b84b..0000000000 --- a/fixtures/Form/nested-default.js +++ /dev/null @@ -1,47 +0,0 @@ -module.exports = { - schema: { - title: "Todo Tasks", - description: "Tasks collection.", - type: "object", - additionalProperties: false, - required: [ - "title", "tasks" - ], - default: { - title: "Default task list", - tasks: [ - {title: "A default task", done: true}, - {title: "Another default task", done: false}, - ] - }, - properties: { - title: { - type: "string", - title: "Tasks list title", - }, - tasks: { - type: "array", - title: "Tasks list", - items: { - type: "object", - properties: { - done: { - type: "boolean", - title: "Done?", - description: "Is that task done already?", - default: true, - }, - title: { - type: "string", - title: "Title", - description: "The task title.", - minLength: 1 - } - } - } - } - } - }, - onSubmit: console.log.bind(console, "submit"), - onError: console.log.bind(console, "errors") -}; diff --git a/fixtures/Form/nested-formData.js b/fixtures/Form/nested-formData.js deleted file mode 100644 index 631993f757..0000000000 --- a/fixtures/Form/nested-formData.js +++ /dev/null @@ -1,47 +0,0 @@ -module.exports = { - schema: { - title: "Todo Tasks", - description: "Tasks collection.", - type: "object", - additionalProperties: false, - required: [ - "title", "tasks" - ], - properties: { - title: { - type: "string", - title: "Tasks list title", - }, - tasks: { - type: "array", - title: "Tasks list", - items: { - type: "object", - properties: { - done: { - type: "boolean", - title: "Done?", - description: "Is that task done already?" - }, - title: { - type: "string", - title: "Title", - description: "The task title.", - minLength: 1 - } - } - } - } - } - }, - formData: { - title: "My tasks", - tasks: [ - {title: "Enjoying JSONSchema", done: true}, - {title: "Enjoying React", done: true}, - {title: "Enjoying react-jsonschema-form", done: false}, - ] - }, - onSubmit: console.log.bind(console, "submit"), - onError: console.log.bind(console, "errors") -}; diff --git a/fixtures/Form/nested-index.js b/fixtures/Form/nested-index.js deleted file mode 100644 index 87589c1ba0..0000000000 --- a/fixtures/Form/nested-index.js +++ /dev/null @@ -1,39 +0,0 @@ -module.exports = { - schema: { - title: "Todo Tasks", - description: "Tasks collection.", - type: "object", - additionalProperties: false, - required: [ - "title", "tasks" - ], - properties: { - title: { - type: "string", - title: "Tasks list title", - }, - tasks: { - type: "array", - title: "Tasks list", - items: { - type: "object", - properties: { - done: { - type: "boolean", - title: "Done?", - description: "Is that task done already?" - }, - title: { - type: "string", - title: "Title", - description: "The task title.", - minLength: 1 - } - } - } - } - } - }, - onSubmit: console.log.bind(console, "submit"), - onError: console.log.bind(console, "errors") -}; diff --git a/fixtures/Form/nested-uiSchema-default.js b/fixtures/Form/nested-uiSchema-default.js deleted file mode 100644 index 77d6f737d3..0000000000 --- a/fixtures/Form/nested-uiSchema-default.js +++ /dev/null @@ -1,63 +0,0 @@ -module.exports = { - schema: { - title: "Todo Tasks", - description: "Tasks collection.", - type: "object", - additionalProperties: false, - required: [ - "title", "tasks" - ], - properties: { - title: { - type: "string", - title: "Tasks list title", - }, - tasks: { - type: "array", - title: "Tasks list", - items: { - type: "object", - properties: { - type: { - type: "string", - title: "Category", - enum: ["coding", "sleeping"] - }, - done: { - type: "boolean", - title: "Done?", - description: "Is that task done already?", - default: false - }, - title: { - type: "string", - title: "Title", - description: "The task title.", - minLength: 1 - } - } - } - } - } - }, - uiSchema: { - title: { - widget: "textarea", - }, - tasks: { - items: { - type: { - widget: "radio" - }, - done: { - widget: "select", - }, - title: { - widget: "textarea" - } - } - } - }, - onSubmit: console.log.bind(console, "submit"), - onError: console.log.bind(console, "errors") -}; diff --git a/fixtures/Form/nested-uiSchema.js b/fixtures/Form/nested-uiSchema.js deleted file mode 100644 index 751d7a9570..0000000000 --- a/fixtures/Form/nested-uiSchema.js +++ /dev/null @@ -1,62 +0,0 @@ -module.exports = { - schema: { - title: "Todo Tasks", - description: "Tasks collection.", - type: "object", - additionalProperties: false, - required: [ - "title", "tasks" - ], - properties: { - title: { - type: "string", - title: "Tasks list title", - }, - tasks: { - type: "array", - title: "Tasks list", - items: { - type: "object", - properties: { - type: { - type: "string", - title: "Category", - enum: ["coding", "sleeping"] - }, - done: { - type: "boolean", - title: "Done?", - description: "Is that task done already?" - }, - title: { - type: "string", - title: "Title", - description: "The task title.", - minLength: 1 - } - } - } - } - } - }, - uiSchema: { - title: { - widget: "textarea", - }, - tasks: { - items: { - type: { - widget: "radio" - }, - done: { - widget: "radio", - }, - title: { - widget: "textarea" - } - } - } - }, - onSubmit: console.log.bind(console, "submit"), - onError: console.log.bind(console, "errors") -}; diff --git a/fixtures/Form/readme-example.js b/fixtures/Form/readme-example.js deleted file mode 100644 index bf903e4bd3..0000000000 --- a/fixtures/Form/readme-example.js +++ /dev/null @@ -1,15 +0,0 @@ -module.exports = { - schema: { - title: "Todo Tasks", - type: "object", - required: ["title"], - properties: { - title: {type: "string", title: "Title", default: "A new task"}, - done: {type: "boolean", title: "Done?", default: false} - } - }, - formData: { - title: "First task", - done: true - } -}; diff --git a/fixtures/Form/simple-formData.js b/fixtures/Form/simple-formData.js deleted file mode 100644 index 52d4b21e5a..0000000000 --- a/fixtures/Form/simple-formData.js +++ /dev/null @@ -1,30 +0,0 @@ -module.exports = { - schema: { - title: "Todo Tasks", - description: "Tasks collection.", - type: "object", - additionalProperties: false, - required: [ - "title" - ], - properties: { - done: { - type: "boolean", - title: "Done?", - description: "Is that task done already?" - }, - title: { - type: "string", - title: "Title", - description: "The task title.", - minLength: 1 - } - } - }, - formData: { - title: "My task", - done: true - }, - onSubmit: console.log.bind(console, "submit"), - onError: console.log.bind(console, "errors") -}; diff --git a/fixtures/Form/simple-index.js b/fixtures/Form/simple-index.js deleted file mode 100644 index a19269d39a..0000000000 --- a/fixtures/Form/simple-index.js +++ /dev/null @@ -1,28 +0,0 @@ -module.exports = { - schema: { - title: "Todo Tasks", - description: "Tasks collection.", - type: "object", - additionalProperties: false, - required: [ - "title" - ], - properties: { - done: { - type: "boolean", - title: "Done?", - description: "Is that task done already?", - default: false - }, - title: { - type: "string", - title: "Title", - description: "The task title.", - minLength: 1, - default: "default value" - } - } - }, - onSubmit: console.log.bind(console, "submit"), - onError: console.log.bind(console, "errors") -}; diff --git a/fixtures/Form/simple-nodefault.js b/fixtures/Form/simple-nodefault.js deleted file mode 100644 index 373a56a2e5..0000000000 --- a/fixtures/Form/simple-nodefault.js +++ /dev/null @@ -1,26 +0,0 @@ -module.exports = { - schema: { - title: "Todo Tasks", - description: "Tasks collection.", - type: "object", - additionalProperties: false, - required: [ - "title" - ], - properties: { - done: { - type: "boolean", - title: "Done?", - description: "Is that task done already?" - }, - title: { - type: "string", - title: "Title", - description: "The task title.", - minLength: 1 - } - } - }, - onSubmit: console.log.bind(console, "submit"), - onError: console.log.bind(console, "errors") -}; diff --git a/fixtures/fields/ArrayField/index.js b/fixtures/fields/ArrayField/index.js deleted file mode 100644 index c3cf575055..0000000000 --- a/fixtures/fields/ArrayField/index.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - schema: { - type: "array", - title: "title", - items: { - type: "string", - title: "item" - } - }, - onChange: console.log.bind(console, "change") -}; diff --git a/fixtures/fields/ArrayField/with-default.js b/fixtures/fields/ArrayField/with-default.js deleted file mode 100644 index 4d9444509d..0000000000 --- a/fixtures/fields/ArrayField/with-default.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = { - schema: { - type: "array", - title: "title", - default: ["default1", "default2"], - items: { - type: "string", - title: "item" - } - }, - onChange: console.log.bind(console, "change") -}; diff --git a/fixtures/fields/ArrayField/with-formData.js b/fixtures/fields/ArrayField/with-formData.js deleted file mode 100644 index 887d128823..0000000000 --- a/fixtures/fields/ArrayField/with-formData.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = { - schema: { - type: "array", - title: "title", - items: { - type: "string", - title: "item" - } - }, - formData: ["item1", "item2"], - onChange: console.log.bind(console, "change") -}; diff --git a/fixtures/fields/ArrayField/with-uiSchema.js b/fixtures/fields/ArrayField/with-uiSchema.js deleted file mode 100644 index 4dad01aff5..0000000000 --- a/fixtures/fields/ArrayField/with-uiSchema.js +++ /dev/null @@ -1,17 +0,0 @@ -module.exports = { - schema: { - type: "array", - title: "title", - items: { - type: "string", - title: "item" - } - }, - uiSchema: { - items: { - widget: "textarea" - } - }, - formData: ["item1", "item2"], - onChange: console.log.bind(console, "change") -}; diff --git a/fixtures/fields/BooleanField/index.js b/fixtures/fields/BooleanField/index.js deleted file mode 100644 index 10391b91d1..0000000000 --- a/fixtures/fields/BooleanField/index.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = { - schema: { - type: "boolean", - title: "My boolean", - }, - onChange: console.log.bind(console, "change") -}; diff --git a/fixtures/fields/BooleanField/with-default.js b/fixtures/fields/BooleanField/with-default.js deleted file mode 100644 index 45c57842b8..0000000000 --- a/fixtures/fields/BooleanField/with-default.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = { - schema: { - type: "boolean", - title: "My boolean", - default: true, - }, - onChange: console.log.bind(console, "change") -}; diff --git a/fixtures/fields/BooleanField/with-formData.js b/fixtures/fields/BooleanField/with-formData.js deleted file mode 100644 index ddcb4983d0..0000000000 --- a/fixtures/fields/BooleanField/with-formData.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = { - schema: { - type: "boolean", - title: "My boolean", - }, - formData: true, - onChange: console.log.bind(console, "change") -}; diff --git a/fixtures/fields/BooleanField/with-uiSchema.js b/fixtures/fields/BooleanField/with-uiSchema.js deleted file mode 100644 index e298ab95f2..0000000000 --- a/fixtures/fields/BooleanField/with-uiSchema.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - schema: { - type: "boolean", - title: "My boolean" - }, - uiSchema: { - widget: "radio" - }, - formData: false, - onChange: console.log.bind(console, "change") -}; diff --git a/fixtures/fields/ObjectField/index.js b/fixtures/fields/ObjectField/index.js deleted file mode 100644 index 719d502e62..0000000000 --- a/fixtures/fields/ObjectField/index.js +++ /dev/null @@ -1,17 +0,0 @@ -module.exports = { - schema: { - type: "object", - title: "object title", - properties: { - string: { - type: "string", - title: "string" - }, - bool: { - type: "boolean", - title: "bool" - } - } - }, - onChange: console.log.bind(console, "change") -}; diff --git a/fixtures/fields/ObjectField/with-default.js b/fixtures/fields/ObjectField/with-default.js deleted file mode 100644 index 54d425553d..0000000000 --- a/fixtures/fields/ObjectField/with-default.js +++ /dev/null @@ -1,21 +0,0 @@ -module.exports = { - schema: { - type: "object", - title: "object title", - default: { - string: "a default string", - bool: true - }, - properties: { - string: { - type: "string", - title: "string" - }, - bool: { - type: "boolean", - title: "bool" - } - } - }, - onChange: console.log.bind(console, "change") -}; diff --git a/fixtures/fields/ObjectField/with-formData.js b/fixtures/fields/ObjectField/with-formData.js deleted file mode 100644 index 041ba3c077..0000000000 --- a/fixtures/fields/ObjectField/with-formData.js +++ /dev/null @@ -1,21 +0,0 @@ -module.exports = { - schema: { - type: "object", - title: "object title", - properties: { - string: { - type: "string", - title: "string" - }, - bool: { - type: "boolean", - title: "bool" - } - } - }, - formData: { - string: "an existing string", - bool: true - }, - onChange: console.log.bind(console, "change") -}; diff --git a/fixtures/fields/ObjectField/with-uiSchema.js b/fixtures/fields/ObjectField/with-uiSchema.js deleted file mode 100644 index 15f5b4e2c4..0000000000 --- a/fixtures/fields/ObjectField/with-uiSchema.js +++ /dev/null @@ -1,25 +0,0 @@ -module.exports = { - schema: { - type: "object", - title: "object title", - properties: { - string: { - type: "string", - title: "string" - }, - bool: { - type: "boolean", - title: "bool" - } - } - }, - uiSchema: { - string: { - widget: "textarea" - }, - bool: { - widget: "select" - } - }, - onChange: console.log.bind(console, "change") -}; diff --git a/fixtures/fields/SchemaField/array.js b/fixtures/fields/SchemaField/array.js deleted file mode 100644 index c3cf575055..0000000000 --- a/fixtures/fields/SchemaField/array.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = { - schema: { - type: "array", - title: "title", - items: { - type: "string", - title: "item" - } - }, - onChange: console.log.bind(console, "change") -}; diff --git a/fixtures/fields/SchemaField/boolean.js b/fixtures/fields/SchemaField/boolean.js deleted file mode 100644 index 10391b91d1..0000000000 --- a/fixtures/fields/SchemaField/boolean.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = { - schema: { - type: "boolean", - title: "My boolean", - }, - onChange: console.log.bind(console, "change") -}; diff --git a/fixtures/fields/SchemaField/date-time.js b/fixtures/fields/SchemaField/date-time.js deleted file mode 100644 index 3f1864a670..0000000000 --- a/fixtures/fields/SchemaField/date-time.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - schema: { - type: "date-time", - title: "date-time" - } -}; diff --git a/fixtures/fields/SchemaField/number.js b/fixtures/fields/SchemaField/number.js deleted file mode 100644 index 538cd60035..0000000000 --- a/fixtures/fields/SchemaField/number.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - schema: { - type: "number", - title: "number" - } -}; diff --git a/fixtures/fields/SchemaField/object.js b/fixtures/fields/SchemaField/object.js deleted file mode 100644 index 719d502e62..0000000000 --- a/fixtures/fields/SchemaField/object.js +++ /dev/null @@ -1,17 +0,0 @@ -module.exports = { - schema: { - type: "object", - title: "object title", - properties: { - string: { - type: "string", - title: "string" - }, - bool: { - type: "boolean", - title: "bool" - } - } - }, - onChange: console.log.bind(console, "change") -}; diff --git a/fixtures/fields/SchemaField/string.js b/fixtures/fields/SchemaField/string.js deleted file mode 100644 index dcf8146043..0000000000 --- a/fixtures/fields/SchemaField/string.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - schema: { - type: "string", - title: "string" - } -}; diff --git a/fixtures/fields/StringField/index.js b/fixtures/fields/StringField/index.js deleted file mode 100644 index dcf8146043..0000000000 --- a/fixtures/fields/StringField/index.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - schema: { - type: "string", - title: "string" - } -}; diff --git a/fixtures/fields/StringField/with-default.js b/fixtures/fields/StringField/with-default.js deleted file mode 100644 index beed5d5041..0000000000 --- a/fixtures/fields/StringField/with-default.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = { - schema: { - type: "string", - title: "string", - default: "a default string" - } -}; diff --git a/fixtures/fields/StringField/with-formData.js b/fixtures/fields/StringField/with-formData.js deleted file mode 100644 index 88effb6c5c..0000000000 --- a/fixtures/fields/StringField/with-formData.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = { - schema: { - type: "string", - title: "string", - }, - formData: "an existing string" -}; diff --git a/fixtures/fields/StringField/with-uiSchema.js b/fixtures/fields/StringField/with-uiSchema.js deleted file mode 100644 index 9a38509435..0000000000 --- a/fixtures/fields/StringField/with-uiSchema.js +++ /dev/null @@ -1,10 +0,0 @@ -module.exports = { - schema: { - type: "string", - title: "string", - }, - uiSchema: { - widget: "textarea" - }, - formData: "an existing string" -}; diff --git a/fixtures/fields/UnsupportedField/index.js b/fixtures/fields/UnsupportedField/index.js deleted file mode 100644 index 9a8355ec7e..0000000000 --- a/fixtures/fields/UnsupportedField/index.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - schema: { - type: "non-existent", - title: "blah" - } -}; diff --git a/fixtures/widgets/CheckboxWidget/index.js b/fixtures/widgets/CheckboxWidget/index.js deleted file mode 100644 index fd11d42c99..0000000000 --- a/fixtures/widgets/CheckboxWidget/index.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = { - type: "boolean", - label: "foo", - onChange: console.log.bind(console, "change") -}; diff --git a/fixtures/widgets/RadioWidget/index.js b/fixtures/widgets/RadioWidget/index.js deleted file mode 100644 index 100750f403..0000000000 --- a/fixtures/widgets/RadioWidget/index.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = { - type: "string", - label: "foo", - defaultValue: "b", - options: ["a", "b"], - onChange: console.log.bind(console, "change") -}; diff --git a/fixtures/widgets/SelectWidget/index.js b/fixtures/widgets/SelectWidget/index.js deleted file mode 100644 index 8febb4be26..0000000000 --- a/fixtures/widgets/SelectWidget/index.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - type: "string", - label: "foo", - options: ["foo", "bar", "baz"], - onChange: console.log.bind(console, "change") -}; diff --git a/fixtures/widgets/TextWidget/index.js b/fixtures/widgets/TextWidget/index.js deleted file mode 100644 index a6f36e5ae5..0000000000 --- a/fixtures/widgets/TextWidget/index.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - type: "string", - label: "foo", - value: "plop", - onChange: console.log.bind(console, "change") -}; diff --git a/fixtures/widgets/Wrapper/index.js b/fixtures/widgets/Wrapper/index.js deleted file mode 100644 index d0c544bf33..0000000000 --- a/fixtures/widgets/Wrapper/index.js +++ /dev/null @@ -1,8 +0,0 @@ -var React = require("react"); - -module.exports = { - type: "string", - label: "foo", - required: true, - children: React.createElement("div", {}, "content") -}; diff --git a/playground/samples/arrays.js b/playground/samples/arrays.js index 5f9b0604ad..48a0ff760a 100644 --- a/playground/samples/arrays.js +++ b/playground/samples/arrays.js @@ -1,6 +1,7 @@ module.exports = { schema: { type: "array", + title: "A list of strings", items: { type: "string", default: "bazinga" diff --git a/playground/samples/numbers.js b/playground/samples/numbers.js index c3b56b5fe2..b7d57d5841 100644 --- a/playground/samples/numbers.js +++ b/playground/samples/numbers.js @@ -1,6 +1,7 @@ module.exports = { schema: { type: "object", + title: "Number fields & widgets", properties: { number: { title: "Number", @@ -14,13 +15,38 @@ module.exports = { type: "number", title: "Number enum", enum: [1, 2, 3] + }, + integerRange: { + title: "Integer range", + type: "integer", + minimum: 42, + maximum: 100, + }, + integerRangeSteps: { + title: "Integer range (by 10)", + type: "integer", + minimum: 50, + maximum: 100, + multipleOf: 10, } } }, - uiSchema: {}, + uiSchema: { + integer: { + widget: "updown" + }, + integerRange: { + widget: "range" + }, + integerRangeSteps: { + widget: "range" + } + }, formData: { number: 3.14, integer: 42, - numberEnum: 2 + numberEnum: 2, + integerRange: 42, + integerRangeSteps: 80, } }; diff --git a/src/components/fields/ArrayField.js b/src/components/fields/ArrayField.js index a44c5a6afe..27dd908f5a 100644 --- a/src/components/fields/ArrayField.js +++ b/src/components/fields/ArrayField.js @@ -63,12 +63,14 @@ class ArrayField extends Component { render() { const {schema, uiSchema, name} = this.props; + const title = name || schema.title; const {items} = this.state; return (