react-jsonschema-form demo
https://github.com/mozilla-services/react-jsonschema-form
HTML
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react-dom.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.3.2/react.min.js"></script>
<script src="https://unpkg.com/react-jsonschema-form@1.6.1/dist/react-jsonschema-form.js"></script>
<div class="container">
<div id="main"></div>
</div>
Babel + JSX
const Form = JSONSchemaForm.default;
const schema = {
"type": "object",
"properties": {
"rtc": {
"title": "Configure Clock",
"type": "object",
"properties": {
"sync": {
"title": "Time Sync Type",
"type": "integer",
"default": 0,
"anyOf": [
{
"title": "Retain time",
"type": "integer",
"enum": [
0
]
},
{
"title": "Auto time",
"type": "integer",
"enum": [
1
]
}
]
}
},
"dependencies": {
"sync": {
"oneOf": [
{
"properties": {
"sync": {
"enum": [
0
]
}
}
},
{
"properties": {
"sync": {
"enum": [
1
]
},
"tolerance": {
"title": "Time sync tolerance",
"type": "string",
/* "minimum": 1,
"maximum": 3600, */
"default": 20
}
}
}
]
}
}
}
}
};
const uiSchema = {
description: {
"ui:widget": "textarea"
}
};
class App extends React.Component {
constructor(props) {
super(props);
this.state = {formData: null}
}
render() {
return <Form schema={schema} uiSchema={uiSchema} formData={this.state.formData} onChange={ ({formData}) => this.setState({formData}) } />;
}
}
ReactDOM.render(<App />,
document.getElementById("main"));