@react-jsonschema-form-custom/material-ui-nd6dp3pzm
v1.0.0
Published
Material UI implementation of react-jsonschema-form
Downloads
1
Readme
React Json Schema Form (@react-jsonschema-form-custom/material-ui-nd6dp3pzm)
Material UI port of jsonschema-form.
Install instructions via npm
npm install --save @react-jsonschema-form-custom/material-ui-nd6dp3pzm
Example Usage
More detailed example can be seen here
// Library
import React from 'react';
import MaterialJsonSchemaForm from '@react-jsonschema-form-custom/material-ui-nd6dp3pzm';
// Internals
const schema = require('./path-to your-schema.json');
const uiSchema = require('./path-to your-ui-schema.json');
const formData = require('./path-to your-ui-formData.json');
const Example () => {
const onSubmit = (value, callback) => {
console.log('onSubmit: %s', JSON.stringify(value)); // eslint-disable-line no-console
setTimeout(() => callback && callback(), 2000); // just an example in real world can be your XHR call
}
const onCancel = () => {
console.log('on reset being called');
}
const onFormChanged = ({ formData }) => {
console.log('onFormChanged: ',formData); // eslint-disable-line no-console
}
const onUpload = (value) => {
console.log('onUpload: ', value); // eslint-disable-line no-console
}
return (
<MaterialJsonSchemaForm
schema={givenSchema}
uiSchema={givenUISchema}
formData={givenFormData}
onCancel={onCancel}
onSubmit={onSubmit}
onUpload={onUpload}
onChange={onFormChanged}
onError={onError}
/* Optional Param for custom functions to be executed for transforming data */
interceptors={{
translateRatings: (givenData, uiData) => ({ givenData, uiData }),
}}
/* Optional Param for custom components */
components={{
customComponent: ({ onChange, ...rest }) => (
<CustomComponent onChange={onChange} formData={givenFormData} uiData={givenUIData} {...rest} />
),
customRating: ({ onChange, ...rest }) => (
<CustomRating onChange={onChange} formData={givenFormData} uiData={givenUIData} {...rest} />
),
}}
/* Optional Param for custom validation */
validations={{
confirmPassword: ({ schema, validations, formData, value }) => value !== formData.pass1 && ({
message: validations.confirmPassword.message,
inline: true,
}),
}}
/* Optional Param to auto submit form on press of enter */
submitOnEnter
/>
);
}
export default Example;