Skip to content

Commit c3b539b

Browse files
author
Mateusz Puczynski
committed
Change prop name and update docs
1 parent 91d012a commit c3b539b

File tree

4 files changed

+21
-18
lines changed

4 files changed

+21
-18
lines changed

docs/validation.md

+11-8
Original file line numberDiff line numberDiff line change
@@ -51,29 +51,32 @@ render((
5151

5252
To have your schemas validated against any other meta schema than draft-07 (the current version of [JSON Schema](http://json-schema.org/)), make sure your schema has a `$schema` attribute that enables the validator to use the correct meta schema. For example:
5353

54-
```json
54+
```json
5555
{
5656
"$schema": "http://json-schema.org/draft-04/schema#",
5757
...
5858
}
5959
```
6060

61-
Note that react-jsonschema-form only supports the latest version of JSON Schema, draft-07, by default. To support additional meta schemas, you need to install `ajv` and import them, then pass your meta schemas through the `metaSchema` prop to your `Form` component:
61+
Note that react-jsonschema-form only supports the latest version of JSON Schema, draft-07, by default. To support additional meta schemas pass them through the `additionalMetaSchemas` prop to your `Form` component:
6262

6363
```jsx
64-
const metaSchema = require("ajv/lib/refs/json-schema-draft-04.json");
64+
const additionalMetaSchemas = require("ajv/lib/refs/json-schema-draft-04.json");
6565

6666
render((
67-
<Form schema={schema}
68-
metaSchema={metaSchema} />
67+
<Form schema={schema}
68+
additionalMetaSchemas={additionalMetaSchemas}/>
6969
), document.getElementById("app"));
7070
```
71-
`metaSchema` also accepts an array of meta schemas:
71+
72+
In this example `schema` passed as props to `Form` component can be validated against draft-07 (default) and by draft-04 (added), depending on the value of `$schema` attribute.
73+
74+
`additionalMetaSchemas` also accepts an array of meta schemas:
7275

7376
```jsx
7477
render((
75-
<Form schema={schema}
76-
metaSchema={[metaSchema1,metaSchema2]} />
78+
<Form schema={schema}
79+
additionalMetaSchemas={[metaSchema1, metaSchema2]} />
7780
), document.getElementById("app"));
7881
```
7982

src/components/Form.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ export default class Form extends Component {
5858
const { definitions } = schema;
5959
const formData = getDefaultFormState(schema, props.formData, definitions);
6060
const retrievedSchema = retrieveSchema(schema, definitions, formData);
61-
const metaSchema = props.metaSchema;
61+
const additionalMetaSchemas = props.additionalMetaSchemas;
6262
const { errors, errorSchema } = mustValidate
63-
? this.validate(formData, schema, metaSchema)
63+
? this.validate(formData, schema, additionalMetaSchemas)
6464
: {
6565
errors: state.errors || [],
6666
errorSchema: state.errorSchema || {},
@@ -80,7 +80,7 @@ export default class Form extends Component {
8080
edit,
8181
errors,
8282
errorSchema,
83-
metaSchema,
83+
additionalMetaSchemas,
8484
};
8585
}
8686

@@ -91,7 +91,7 @@ export default class Form extends Component {
9191
validate(
9292
formData,
9393
schema = this.props.schema,
94-
metaSchema = this.props.metaSchema
94+
additionalMetaSchemas = this.props.additionalMetaSchemas
9595
) {
9696
const { validate, transformErrors } = this.props;
9797
const { definitions } = this.getRegistry();
@@ -101,7 +101,7 @@ export default class Form extends Component {
101101
resolvedSchema,
102102
validate,
103103
transformErrors,
104-
metaSchema
104+
additionalMetaSchemas
105105
);
106106
}
107107

@@ -300,7 +300,7 @@ if (process.env.NODE_ENV !== "production") {
300300
transformErrors: PropTypes.func,
301301
safeRenderCompletion: PropTypes.bool,
302302
formContext: PropTypes.object,
303-
metaSchema: PropTypes.oneOfType(
303+
additionalMetaSchemas: PropTypes.oneOfType(
304304
PropTypes.object,
305305
PropTypes.arrayOf(PropTypes.object)
306306
),

src/validate.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,11 @@ export default function validateFormData(
157157
schema,
158158
customValidate,
159159
transformErrors,
160-
metaSchema
160+
additionalMetaSchemas
161161
) {
162162
// add more schemas to validate against
163-
if (!addedMetaSchemas && metaSchema) {
164-
ajv.addMetaSchema(metaSchema);
163+
if (!addedMetaSchemas && additionalMetaSchemas) {
164+
ajv.addMetaSchema(additionalMetaSchemas);
165165
addedMetaSchemas = true;
166166
}
167167
let validationErrors = null;

test/validate_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ describe("Validation", () => {
768768
schema,
769769
formData,
770770
liveValidate: true,
771-
metaSchema: require("ajv/lib/refs/json-schema-draft-04.json"),
771+
additionalMetaSchemas: require("ajv/lib/refs/json-schema-draft-04.json"),
772772
onSubmit,
773773
onError,
774774
});

0 commit comments

Comments
 (0)