Skip to content

Commit 8bd9017

Browse files
committed
Add newElementDefaultUiSchema mod
1 parent 14d07d2 commit 8bd9017

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-5
lines changed

docs/Mods.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ declare type Mods = {|
4141
$ref?: string,
4242
default?: string,
4343
},
44+
newElementDefaultUiSchema?: { [string]: any },
4445
|};
4546
```
4647

docs/Usage.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,9 @@ mods = {
271271

272272
This will hide these Input Types on the `FormBuilder` component.
273273

274-
### Default New Form Element (newElementDefaultDataOptions)
274+
### Default New Form Element (newElementDefaultDataOptions and newElementDefaultUiSchema)
275275

276-
By default, when adding a new form element, the dataOptions are set to:
276+
By default, when adding a new form element, the schema for the new form element is set to:
277277

278278
```react
279279
{
@@ -283,7 +283,7 @@ By default, when adding a new form element, the dataOptions are set to:
283283
}
284284
```
285285

286-
This means that by default, a new form element has the "Short answer" input type. If you wish to override this (for example, if the "Short answer" input is deactivated), you can do so by using the `newElementDefaultDataOptions` mod. For example, setting the mods to the following:
286+
and the UI schema is not set at all. This means that by default, a new form element has the "Short answer" input type. If you wish to override this (for example, if the "Short answer" input is deactivated), you can do so by using the `newElementDefaultDataOptions` and `newElementDefaultUiSchema` mods. For example, setting the mods to the following:
287287

288288
```react
289289
mods = {
@@ -294,7 +294,17 @@ mods = {
294294
};
295295
```
296296

297-
will default new form elements to a "Reference" type to some definition "firstNames" defined in the schema.
297+
will default new form elements to a "Reference" type to some definition "firstNames" defined in the schema. Setting the mods to the following:
298+
299+
```react
300+
mods = {
301+
newElementDefaultUiSchema: {
302+
'ui:widget': 'customWidget',
303+
}
304+
};
305+
```
306+
307+
will set the UI schema for a new element to use the `customWidget` widget.
298308

299309
### Styling
300310

flow-libdef/@ginkgo-bioworks/react-json-schema-form-builder_v1.x.x/flow_v0.92.x-/react-json-schema-form-builder_v1.x.x.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ declare module '@ginkgo-bioworks/react-json-schema-form-builder' {
8989
showFormHead?: boolean,
9090
deactivatedFormInputs?: Array<string>,
9191
newElementDefaultDataOptions?: DataOptions,
92+
newElementDefaultUiSchema?: { [string]: any },
9293
|};
9394

9495
declare type FormBuilderProps = {|

src/formBuilder/types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ export type Mods = {
136136
showFormHead?: boolean,
137137
deactivatedFormInputs?: Array<string>,
138138
newElementDefaultDataOptions?: DataOptions,
139+
newElementDefaultUiSchema?: { [string]: any },
139140
};
140141

141142
export type FormInput = FormInputType<Mods>;

src/formBuilder/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ export function addCardObj(parameters: {
915915
name: `newInput${i}`,
916916
required: false,
917917
dataOptions: dataOptions,
918-
uiOptions: {},
918+
uiOptions: (mods && mods.newElementDefaultUiSchema) || {},
919919
propType: 'card',
920920
schema: {},
921921
uischema: {},

0 commit comments

Comments
 (0)