|
| 1 | +# RJSF Schemas |
| 2 | + |
| 3 | +RJSF, or React JSON Schema Form, schemas play a crucial role in defining the structure and behavior of forms. These schemas, written in JSON format, provide a blueprint for rendering forms dynamically and handling user input effectively. |
| 4 | + |
| 5 | +### What are RJSF Schemas? |
| 6 | + |
| 7 | +RJSF Schemas, based on the React JSON Schema Form library, define the structure, validation rules, and UI elements of dynamic forms in a standardized way. They enable the creation of consistent and flexible forms across our applications. |
| 8 | + |
| 9 | +### How to Use RJSF Schemas |
| 10 | + |
| 11 | +1. **Importing Schemas:** |
| 12 | + Include the required schema in your React component by importing it. For example: |
| 13 | + |
| 14 | + ```javascript |
| 15 | + import MyFormSchema from '@layer5/sistent'; |
| 16 | + ``` |
| 17 | + |
| 18 | +1. **Rendering Forms:** |
| 19 | + Integrate the schema into your component to render the form dynamically. Use already created generic RJSF components or use RJSF Form component directly. |
| 20 | + |
| 21 | + ```javascript |
| 22 | + import { sampleSchema, sampleUiSchema } from '@layer5/sistent'; |
| 23 | + <Form schema={sampleSchema} uiSchema={sampleUiSchema} onSubmit={handleFormSubmission} />; |
| 24 | + ``` |
| 25 | + |
| 26 | +1. **Customization:** |
| 27 | + Adjust the schema properties to tailor the form's appearance and behavior. Refer to the specific schema's documentation for customization options. |
| 28 | + |
| 29 | +### File Conventions for Schemas |
| 30 | + |
| 31 | +Follow a consistent file structure convention to enhance clarity and organization when adding new schema: |
| 32 | + |
| 33 | +1. Use the same name as the schema for the directory. |
| 34 | +1. Use CamelCase for multi-word schema names, e.g., UserRegistrationFormSchema. |
| 35 | +1. Create two separate files, schema.tsx and uiSchema.tsx, to store both schemas separately. |
| 36 | + |
| 37 | +### Naming Conventions for Schemas |
| 38 | + |
| 39 | +Follow a consistent naming convention to enhance clarity and organization when adding new schema: |
| 40 | + |
| 41 | +1. Use descriptive names that convey the purpose of the form. |
| 42 | +1. CamelCase for multi-word schema names, e.g., UserRegistrationFormSchema. |
| 43 | +1. Include "Schema" in the name to explicitly indicate that it's a schema, e.g., ProfileSettingsSchema. |
| 44 | +1. Include "UiSchema" in the name to explicitly indicate that it's a UI schema, e.g., ProfileSettingsUiSchema. |
| 45 | + |
| 46 | +### Custom Properties |
| 47 | + |
| 48 | +In addition to the properties offered by the JSON schema, we have introduced the following custom properties that you can include in new schema: |
| 49 | + |
| 50 | +1. `x-rjsf-grid-area:` This property accepts an integer that defines the width of the field. For instance, specifying 6 means it will take up half of the parent width, while 12 signifies full width. |
| 51 | +1. `x-encode-in-uri:` When set to true, this property enables RJSF to encode data in URI format and return it. |
0 commit comments