Skip to content

Commit 418b080

Browse files
IATW updates readme for draupnirInstanceForm
1 parent 5e65c37 commit 418b080

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,59 @@ const FormSection = () => {
9999
};
100100
```
101101

102+
## If you need more refine control
103+
104+
## DraupnirInstanceForm
105+
106+
The `DraupnirInstanceForm` component is a wrapper that provides the form context for the Draupnir form.
107+
108+
### Props
109+
110+
- **schema**: _Required._ The JSON schema that defines the structure of the form.
111+
- **onSubmit**: _Required._ A function to handle form submission.
112+
- **mode**: Optional. Controls when validations should run. Possible values are 'onChange', 'onBlur', 'all', 'onSubmit'. Default is 'onSubmit'.
113+
- **defaultValues**: Optional. An object to override the default values of the form fields.
114+
115+
### Example
116+
117+
```typescript
118+
const App = () => (
119+
<DraupnirRoot widgets={widgets}>
120+
<DraupnirInstanceProvider
121+
schema={schema}
122+
mode={'onChange'}
123+
defaultValues={{}}
124+
>
125+
<DraupnirInstanceForm onSubmit={handleOnSubmit}>
126+
<DraupnirInstanceFormField schema={schema} />
127+
// your elements that needs to access form events.
128+
</DraupnirInstanceForm>
129+
<FormSection />
130+
</DraupnirInstanceProvider>
131+
</DraupnirRoot>
132+
);
133+
```
134+
135+
If should either use `DraupnirForm` or `DraupnirInstanceForm` for one `DraupnirInstanceProvider`.
136+
137+
## DraupnirInstanceFormField
138+
139+
The `DraupnirInstanceFormField` component is used to render individual form fields based on the JSON schema. It automatically handles the rendering and validation of the field according to the schema definition.
140+
141+
### Example
142+
143+
```typescript
144+
const FormSection = () => {
145+
return (
146+
<div>
147+
<DraupnirInstanceFormField schema={schema} /> // this renders your form //
148+
you can basically call this anywhere inside boundary of
149+
DraupnirInstanceForm. // i.e., more customization
150+
</div>
151+
);
152+
};
153+
```
154+
102155
## Example Schema
103156

104157
```typescript

0 commit comments

Comments
 (0)