react-jsonschema-form demo
https://github.com/mozilla-services/react-jsonschema-form
HTML
<script src="https://npmcdn.com/react-jsonschema-form/dist/react-jsonschema-form.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<div class="container">
<div id="main"></div>
</div>
Babel + JSX
const Form = JSONSchemaForm.default;
const schema = {
title: "react-jsonschema-form demo",
type: "object",
required: ["name"],
properties: {
name: {type: "string", minLength: 3},
description: {type: "string"}
}
};
const uiSchema = {
description: {
"ui:widget": "textarea"
}
};
function Tpl(props) {
const {id, classNames, label, help, required, description, rawErrors=[], children} = props;
return (
<div className={classNames}>
<label htmlFor={id}>{label}{required ? "*" : null}</label>
{description}
{children}
{rawErrors.map(error => <div style={{color: "blue"}}><h1>{error}</h1></div>)}
{help}
</div>
);
}
React.render(<Form schema={schema} uiSchema={uiSchema} FieldTemplate={Tpl} liveValidate/>,
document.getElementById("main"));