diff --git a/playground/app.js b/playground/app.js index c792554327..16fa86c136 100644 --- a/playground/app.js +++ b/playground/app.js @@ -7,6 +7,8 @@ import { shouldRender } from "../src/utils"; import { samples } from "./samples"; import Form from "../src"; +import SchemaField from "../src/components/fields/SchemaField" + // Import a few CodeMirror themes; these are used to match alternative // bootstrap ones. import "codemirror/lib/codemirror.css"; @@ -161,6 +163,51 @@ class GeoPosition extends Component { } } +class MultiArray extends Component { + constructor(props) { + super(props); + this.state = {items: [], formData: props.formData}; + } + + onClick = (e) => { + let value = e.target.value; + let selectedSchema = this.props.schema.items.oneOf.find(i => i.title === value); + + let newItems = this.state.items; + newItems.push(selectedSchema); + this.setState({items: newItems}); + } + + renderOptions() { + return this.props.schema.items.oneOf.map(option => ) + } + + renderWidgets() { + let schema = { + type: 'array', + items: this.state.items + }; + let {idSchema, registry, formData, onChange, errorSchema} = this.props; + return + } + + render() { + return ( +
+ {this.renderWidgets()} +
+ +
    + {this.renderOptions()} +
+
+
+ ); + } +} + class Editor extends Component { constructor(props) { super(props); @@ -357,7 +404,7 @@ class App extends Component { uiSchema={uiSchema} formData={formData} onChange={this.onFormDataChange} - fields={{geo: GeoPosition}} + fields={{geo: GeoPosition, multiArray: MultiArray}} validate={validate} onError={log("errors")} />} diff --git a/playground/index.html b/playground/index.html index 9490b847fb..84dbbdbfa2 100644 --- a/playground/index.html +++ b/playground/index.html @@ -6,6 +6,8 @@ react-jsonschema-form playground + + diff --git a/playground/samples/index.js b/playground/samples/index.js index 625a755ff5..dab8b1c630 100644 --- a/playground/samples/index.js +++ b/playground/samples/index.js @@ -11,6 +11,7 @@ import large from "./large"; import date from "./date"; import validation from "./validation"; import files from "./files"; +import oneOf from "./oneOf"; export const samples = { Simple: simple, @@ -26,4 +27,5 @@ export const samples = { "Date & time": date, Validation: validation, Files: files, + OneOf: oneOf }; diff --git a/playground/samples/oneOf.js b/playground/samples/oneOf.js new file mode 100644 index 0000000000..a4239a6247 --- /dev/null +++ b/playground/samples/oneOf.js @@ -0,0 +1,39 @@ +module.exports = { + schema: { + "type": "object", + "properties": { + "multiArray": { + "type": "array", + "title": "OneOf Array", + "items": { + "oneOf": [ + { + "type": "string", + "title": "String" + }, + { + "type": "number", + "title": "Number" + }, + { + "type": "object", + "title": "Object", + "properties": { + "number": { + "type": "number", + "title": "Number" + }, + "boolean": { + "type": "boolean", + "title": "boolean" + } + } + } + ] + } + } + } + }, + uiSchema: {multiArray: {"ui:field": "multiArray"}}, + formData: {} +};