From 0a9bae93f265a034e737e79ffc8f428f474a7645 Mon Sep 17 00:00:00 2001 From: blam Date: Mon, 20 Nov 2023 12:16:41 +0100 Subject: [PATCH] docs: add examples --- .../docs/docs/api-reference/form-props.md | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/packages/docs/docs/api-reference/form-props.md b/packages/docs/docs/api-reference/form-props.md index 147c1b6b29..7542ebc4d7 100644 --- a/packages/docs/docs/api-reference/form-props.md +++ b/packages/docs/docs/api-reference/form-props.md @@ -122,6 +122,68 @@ render( ); ``` +### `allOf` + +Optional enumerated flag controlling how empty defaults are populated when `allOf` schemas are provided, defaulting to `skipDefaults`: + +| Flag Value | Description | +| ------------------ | -------------------------------------------------------------------------------------------- | +| `skipDefaults` | Skip parsing defaults from `allOf` schemas | +| `populateDefaults` | Generate default values for properties in the `allOf` schema including `if-then-else` syntax | + +```tsx +import { RJSFSchema } from '@rjsf/utils'; +import validator from '@rjsf/validator-ajv8'; + +const schema: RJSFSchema = { + title: 'Example', + type: 'object', + properties: { + animalInfo: { + properties: { + animal: { + type: 'string', + default: 'Cat', + enum: ['Cat', 'Fish'], + }, + }, + allOf: [ + { + if: { + properties: { + animal: { + const: 'Cat', + }, + }, + }, + then: { + properties: { + food: { + type: 'string', + default: 'meat', + enum: ['meat', 'grass', 'fish'], + }, + }, + required: ['food'], + }, + }, + ], + }, + }, +}; + +render( +
, + document.getElementById('app') +); +``` + ## disabled It's possible to disable the whole form by setting the `disabled` prop. The `disabled` prop is then forwarded down to each field of the form.