Skip to content

Conversation

@n1k0
Copy link
Collaborator

@n1k0 n1k0 commented Jan 9, 2016

Custom SchemaField

Warning: This is a powerful feature as you can override the whole form behavior and easily mess it up. Handle with care.

You can provide your own implementation of the SchemaField base React component for rendering any JSONSchema field type, including objects and arrays. This is useful when you want to augment a given field type with supplementary powers.

To proceed so, you can pass a SchemaField prop to the Form component instance; here's a rather silly example wrapping the standard SchemaField lib component:

import SchemaField from "react-jsonschema-form/lib/components/fields/SchemaField";

const CustomSchemaField = function(props) {
  return (
    <div id="custom">
      <p>Yeah, I'm pretty dumb.</p>
      <SchemaField {...props} />
    </div>
  );
};

render((
  <Form schema={schema}
        uiSchema={uiSchema}
        formData={formData}
        SchemaField={CustomSchemaField} />
), document.getElementById("app"));

If you're curious how this could ever be useful, have a look at the Kinto formbuilder repository to see how it's used to provide editing capabilities to any form field.

almet and others added 4 commits January 6, 2016 18:26
In the previous commit, we tried to use the context concept from React and
finally decided to pass it directly via the props as it seems clearer.

This commit generates a warning when running the tests. Needs to be
investigated.
@n1k0 n1k0 force-pushed the dynamic-schema-field branch from 5e757a7 to 556032c Compare January 9, 2016 09:43
n1k0 added a commit that referenced this pull request Jan 9, 2016
@n1k0 n1k0 merged commit 530bdf8 into master Jan 9, 2016
@n1k0 n1k0 deleted the dynamic-schema-field branch January 9, 2016 09:50
epicfaace pushed a commit that referenced this pull request Feb 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants