@rjsf/core 6.0.0-beta.2 → 6.0.0-beta.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core.umd.js +469 -360
- package/dist/{index.js → index.cjs} +640 -519
- package/dist/index.cjs.map +7 -0
- package/dist/index.esm.js +706 -566
- package/dist/index.esm.js.map +4 -4
- package/lib/components/Form.d.ts +66 -16
- package/lib/components/Form.d.ts.map +1 -1
- package/lib/components/Form.js +138 -59
- package/lib/components/fields/ArrayField.d.ts +17 -7
- package/lib/components/fields/ArrayField.d.ts.map +1 -1
- package/lib/components/fields/ArrayField.js +92 -59
- package/lib/components/fields/BooleanField.d.ts.map +1 -1
- package/lib/components/fields/BooleanField.js +7 -2
- package/lib/components/fields/LayoutGridField.d.ts +27 -25
- package/lib/components/fields/LayoutGridField.d.ts.map +1 -1
- package/lib/components/fields/LayoutGridField.js +83 -53
- package/lib/components/fields/LayoutHeaderField.d.ts +1 -1
- package/lib/components/fields/LayoutHeaderField.js +3 -3
- package/lib/components/fields/LayoutMultiSchemaField.js +6 -5
- package/lib/components/fields/MultiSchemaField.d.ts.map +1 -1
- package/lib/components/fields/MultiSchemaField.js +13 -9
- package/lib/components/fields/NullField.js +3 -3
- package/lib/components/fields/NumberField.d.ts.map +1 -1
- package/lib/components/fields/NumberField.js +3 -3
- package/lib/components/fields/ObjectField.d.ts +3 -3
- package/lib/components/fields/ObjectField.d.ts.map +1 -1
- package/lib/components/fields/ObjectField.js +18 -25
- package/lib/components/fields/SchemaField.d.ts.map +1 -1
- package/lib/components/fields/SchemaField.js +17 -17
- package/lib/components/fields/StringField.d.ts.map +1 -1
- package/lib/components/fields/StringField.js +7 -2
- package/lib/components/templates/ArrayFieldDescriptionTemplate.d.ts +1 -1
- package/lib/components/templates/ArrayFieldDescriptionTemplate.js +3 -3
- package/lib/components/templates/ArrayFieldItemButtonsTemplate.js +2 -2
- package/lib/components/templates/ArrayFieldTemplate.js +3 -3
- package/lib/components/templates/ArrayFieldTitleTemplate.d.ts +1 -1
- package/lib/components/templates/ArrayFieldTitleTemplate.js +3 -3
- package/lib/components/templates/FieldErrorTemplate.js +2 -2
- package/lib/components/templates/FieldHelpTemplate.js +2 -2
- package/lib/components/templates/MultiSchemaFieldTemplate.d.ts +8 -0
- package/lib/components/templates/MultiSchemaFieldTemplate.d.ts.map +1 -0
- package/lib/components/templates/MultiSchemaFieldTemplate.js +10 -0
- package/lib/components/templates/ObjectFieldTemplate.js +2 -2
- package/lib/components/templates/UnsupportedField.js +3 -3
- package/lib/components/templates/index.d.ts.map +1 -1
- package/lib/components/templates/index.js +2 -0
- package/lib/components/widgets/AltDateWidget.d.ts.map +1 -1
- package/lib/components/widgets/AltDateWidget.js +15 -18
- package/lib/components/widgets/CheckboxesWidget.js +2 -2
- package/lib/getDefaultRegistry.d.ts.map +1 -1
- package/lib/getDefaultRegistry.js +2 -1
- package/lib/getTestRegistry.d.ts +5 -0
- package/lib/getTestRegistry.d.ts.map +1 -0
- package/lib/getTestRegistry.js +19 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +18 -19
- package/src/components/Form.tsx +183 -73
- package/src/components/fields/ArrayField.tsx +99 -67
- package/src/components/fields/BooleanField.tsx +12 -3
- package/src/components/fields/LayoutGridField.tsx +95 -82
- package/src/components/fields/LayoutHeaderField.tsx +3 -3
- package/src/components/fields/LayoutMultiSchemaField.tsx +5 -5
- package/src/components/fields/MultiSchemaField.tsx +51 -35
- package/src/components/fields/NullField.tsx +3 -3
- package/src/components/fields/NumberField.tsx +11 -3
- package/src/components/fields/ObjectField.tsx +19 -36
- package/src/components/fields/SchemaField.tsx +24 -30
- package/src/components/fields/StringField.tsx +12 -3
- package/src/components/templates/ArrayFieldDescriptionTemplate.tsx +3 -3
- package/src/components/templates/ArrayFieldItemButtonsTemplate.tsx +5 -5
- package/src/components/templates/ArrayFieldTemplate.tsx +5 -5
- package/src/components/templates/ArrayFieldTitleTemplate.tsx +3 -3
- package/src/components/templates/BaseInputTemplate.tsx +3 -3
- package/src/components/templates/FieldErrorTemplate.tsx +2 -2
- package/src/components/templates/FieldHelpTemplate.tsx +2 -2
- package/src/components/templates/MultiSchemaFieldTemplate.tsx +20 -0
- package/src/components/templates/ObjectFieldTemplate.tsx +5 -5
- package/src/components/templates/UnsupportedField.tsx +3 -3
- package/src/components/templates/WrapIfAdditionalTemplate.tsx +1 -1
- package/src/components/templates/index.ts +2 -0
- package/src/components/widgets/AltDateWidget.tsx +21 -23
- package/src/components/widgets/CheckboxWidget.tsx +2 -2
- package/src/components/widgets/CheckboxesWidget.tsx +3 -3
- package/src/components/widgets/RadioWidget.tsx +1 -1
- package/src/components/widgets/SelectWidget.tsx +1 -1
- package/src/components/widgets/TextareaWidget.tsx +1 -1
- package/src/getDefaultRegistry.ts +10 -1
- package/src/getTestRegistry.tsx +34 -0
- package/src/index.ts +2 -1
- package/dist/index.js.map +0 -7
|
@@ -7,11 +7,13 @@ import {
|
|
|
7
7
|
allowAdditionalItems,
|
|
8
8
|
isCustomWidget,
|
|
9
9
|
optionsList,
|
|
10
|
+
toFieldPathId,
|
|
10
11
|
ArrayFieldTemplateProps,
|
|
11
12
|
ErrorSchema,
|
|
13
|
+
FieldPathId,
|
|
14
|
+
FieldPathList,
|
|
12
15
|
FieldProps,
|
|
13
16
|
FormContextType,
|
|
14
|
-
IdSchema,
|
|
15
17
|
RJSFSchema,
|
|
16
18
|
StrictRJSFSchema,
|
|
17
19
|
TranslatableString,
|
|
@@ -22,7 +24,7 @@ import cloneDeep from 'lodash/cloneDeep';
|
|
|
22
24
|
import get from 'lodash/get';
|
|
23
25
|
import isObject from 'lodash/isObject';
|
|
24
26
|
import set from 'lodash/set';
|
|
25
|
-
import
|
|
27
|
+
import uniqueId from 'lodash/uniqueId';
|
|
26
28
|
|
|
27
29
|
/** Type used to represent the keyed form data used in the state */
|
|
28
30
|
type KeyedFormDataType<T> = { key: string; item: T };
|
|
@@ -37,7 +39,7 @@ type ArrayFieldState<T> = {
|
|
|
37
39
|
|
|
38
40
|
/** Used to generate a unique ID for an element in a row */
|
|
39
41
|
function generateRowId() {
|
|
40
|
-
return
|
|
42
|
+
return uniqueId('rjsf-array-item-');
|
|
41
43
|
}
|
|
42
44
|
|
|
43
45
|
/** Converts the `formData` into `KeyedFormDataType` data, using the `generateRowId()` function to create the key
|
|
@@ -198,7 +200,7 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
|
|
|
198
200
|
event.preventDefault();
|
|
199
201
|
}
|
|
200
202
|
|
|
201
|
-
const { onChange, errorSchema } = this.props;
|
|
203
|
+
const { onChange, errorSchema, fieldPathId } = this.props;
|
|
202
204
|
const { keyedFormData } = this.state;
|
|
203
205
|
// refs #195: revalidate to ensure properly reindexing errors
|
|
204
206
|
let newErrorSchema: ErrorSchema<T>;
|
|
@@ -229,7 +231,8 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
|
|
|
229
231
|
keyedFormData: newKeyedFormData,
|
|
230
232
|
updatedKeyedFormData: true,
|
|
231
233
|
},
|
|
232
|
-
|
|
234
|
+
// add click will pass the empty `path` array to the onChange which adds the appropriate path
|
|
235
|
+
() => onChange(keyedToPlainFormData(newKeyedFormData), fieldPathId.path, newErrorSchema as ErrorSchema<T[]>),
|
|
233
236
|
);
|
|
234
237
|
}
|
|
235
238
|
|
|
@@ -267,7 +270,7 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
|
|
|
267
270
|
event.preventDefault();
|
|
268
271
|
}
|
|
269
272
|
|
|
270
|
-
const { onChange, errorSchema } = this.props;
|
|
273
|
+
const { onChange, errorSchema, fieldPathId } = this.props;
|
|
271
274
|
const { keyedFormData } = this.state;
|
|
272
275
|
// refs #195: revalidate to ensure properly reindexing errors
|
|
273
276
|
let newErrorSchema: ErrorSchema<T>;
|
|
@@ -298,7 +301,7 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
|
|
|
298
301
|
keyedFormData: newKeyedFormData,
|
|
299
302
|
updatedKeyedFormData: true,
|
|
300
303
|
},
|
|
301
|
-
() => onChange(keyedToPlainFormData(newKeyedFormData), newErrorSchema as ErrorSchema<T[]>),
|
|
304
|
+
() => onChange(keyedToPlainFormData(newKeyedFormData), fieldPathId.path, newErrorSchema as ErrorSchema<T[]>),
|
|
302
305
|
);
|
|
303
306
|
};
|
|
304
307
|
};
|
|
@@ -314,7 +317,7 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
|
|
|
314
317
|
if (event) {
|
|
315
318
|
event.preventDefault();
|
|
316
319
|
}
|
|
317
|
-
const { onChange, errorSchema } = this.props;
|
|
320
|
+
const { onChange, errorSchema, fieldPathId } = this.props;
|
|
318
321
|
const { keyedFormData } = this.state;
|
|
319
322
|
// refs #195: revalidate to ensure properly reindexing errors
|
|
320
323
|
let newErrorSchema: ErrorSchema<T>;
|
|
@@ -335,7 +338,7 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
|
|
|
335
338
|
keyedFormData: newKeyedFormData,
|
|
336
339
|
updatedKeyedFormData: true,
|
|
337
340
|
},
|
|
338
|
-
() => onChange(keyedToPlainFormData(newKeyedFormData), newErrorSchema as ErrorSchema<T[]>),
|
|
341
|
+
() => onChange(keyedToPlainFormData(newKeyedFormData), fieldPathId.path, newErrorSchema as ErrorSchema<T[]>),
|
|
339
342
|
);
|
|
340
343
|
};
|
|
341
344
|
};
|
|
@@ -353,7 +356,7 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
|
|
|
353
356
|
event.preventDefault();
|
|
354
357
|
event.currentTarget.blur();
|
|
355
358
|
}
|
|
356
|
-
const { onChange, errorSchema } = this.props;
|
|
359
|
+
const { onChange, errorSchema, fieldPathId } = this.props;
|
|
357
360
|
let newErrorSchema: ErrorSchema<T>;
|
|
358
361
|
if (errorSchema) {
|
|
359
362
|
newErrorSchema = {};
|
|
@@ -385,7 +388,7 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
|
|
|
385
388
|
{
|
|
386
389
|
keyedFormData: newKeyedFormData,
|
|
387
390
|
},
|
|
388
|
-
() => onChange(keyedToPlainFormData(newKeyedFormData), newErrorSchema as ErrorSchema<T[]>),
|
|
391
|
+
() => onChange(keyedToPlainFormData(newKeyedFormData), fieldPathId.path, newErrorSchema as ErrorSchema<T[]>),
|
|
389
392
|
);
|
|
390
393
|
};
|
|
391
394
|
};
|
|
@@ -396,22 +399,14 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
|
|
|
396
399
|
* @param index - The index of the item being changed
|
|
397
400
|
*/
|
|
398
401
|
onChangeForIndex = (index: number) => {
|
|
399
|
-
return (value: any, newErrorSchema?: ErrorSchema<T>, id?: string) => {
|
|
400
|
-
const {
|
|
401
|
-
|
|
402
|
-
const newFormData = arrayData.map((item: T, i: number) => {
|
|
402
|
+
return (value: any, path: FieldPathList, newErrorSchema?: ErrorSchema<T>, id?: string) => {
|
|
403
|
+
const { onChange } = this.props;
|
|
404
|
+
onChange(
|
|
403
405
|
// We need to treat undefined items as nulls to have validation.
|
|
404
406
|
// See https://github.com/tdegrunt/jsonschema/issues/206
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
onChange(
|
|
409
|
-
newFormData,
|
|
410
|
-
errorSchema &&
|
|
411
|
-
errorSchema && {
|
|
412
|
-
...errorSchema,
|
|
413
|
-
[index]: newErrorSchema,
|
|
414
|
-
},
|
|
407
|
+
value === undefined ? null : value,
|
|
408
|
+
path,
|
|
409
|
+
newErrorSchema as ErrorSchema<T[]>,
|
|
415
410
|
id,
|
|
416
411
|
);
|
|
417
412
|
};
|
|
@@ -419,14 +414,48 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
|
|
|
419
414
|
|
|
420
415
|
/** Callback handler used to change the value for a checkbox */
|
|
421
416
|
onSelectChange = (value: any) => {
|
|
422
|
-
const { onChange,
|
|
423
|
-
|
|
417
|
+
const { onChange, fieldPathId } = this.props;
|
|
418
|
+
// select change will pass an empty `path` array since the `ObjectField` will add the path value automatically
|
|
419
|
+
onChange(value, fieldPathId.path, undefined, fieldPathId && fieldPathId.$id);
|
|
424
420
|
};
|
|
425
421
|
|
|
422
|
+
/** Helper method to compute item UI schema for both normal and fixed arrays
|
|
423
|
+
* Handles both static object and dynamic function cases
|
|
424
|
+
*
|
|
425
|
+
* @param uiSchema - The parent UI schema containing items definition
|
|
426
|
+
* @param item - The item data
|
|
427
|
+
* @param index - The index of the item
|
|
428
|
+
* @param formContext - The form context
|
|
429
|
+
* @returns The computed UI schema for the item
|
|
430
|
+
*/
|
|
431
|
+
private computeItemUiSchema(
|
|
432
|
+
uiSchema: UiSchema<T[], S, F>,
|
|
433
|
+
item: T,
|
|
434
|
+
index: number,
|
|
435
|
+
formContext: F,
|
|
436
|
+
): UiSchema<T[], S, F> | undefined {
|
|
437
|
+
if (typeof uiSchema.items === 'function') {
|
|
438
|
+
try {
|
|
439
|
+
// Call the function with item data, index, and form context
|
|
440
|
+
// TypeScript now correctly infers the types thanks to the ArrayElement type in UiSchema
|
|
441
|
+
const result = uiSchema.items(item, index, formContext);
|
|
442
|
+
// Only use the result if it's truthy
|
|
443
|
+
return result as UiSchema<T[], S, F>;
|
|
444
|
+
} catch (e) {
|
|
445
|
+
console.error(`Error executing dynamic uiSchema.items function for item at index ${index}:`, e);
|
|
446
|
+
// Fall back to undefined to allow the field to still render
|
|
447
|
+
return undefined;
|
|
448
|
+
}
|
|
449
|
+
} else {
|
|
450
|
+
// Static object case - preserve undefined to maintain backward compatibility
|
|
451
|
+
return uiSchema.items as UiSchema<T[], S, F> | undefined;
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
|
|
426
455
|
/** Renders the `ArrayField` depending on the specific needs of the schema and uischema elements
|
|
427
456
|
*/
|
|
428
457
|
render() {
|
|
429
|
-
const { schema, uiSchema,
|
|
458
|
+
const { schema, uiSchema, fieldPathId, registry } = this.props;
|
|
430
459
|
const { schemaUtils, translateString } = registry;
|
|
431
460
|
if (!(ITEMS_KEY in schema)) {
|
|
432
461
|
const uiOptions = getUiOptions<T[], S, F>(uiSchema);
|
|
@@ -439,7 +468,7 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
|
|
|
439
468
|
return (
|
|
440
469
|
<UnsupportedFieldTemplate
|
|
441
470
|
schema={schema}
|
|
442
|
-
|
|
471
|
+
fieldPathId={fieldPathId}
|
|
443
472
|
reason={translateString(TranslatableString.MissingItems)}
|
|
444
473
|
registry={registry}
|
|
445
474
|
/>
|
|
@@ -468,7 +497,7 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
|
|
|
468
497
|
schema,
|
|
469
498
|
uiSchema = {},
|
|
470
499
|
errorSchema,
|
|
471
|
-
|
|
500
|
+
fieldPathId,
|
|
472
501
|
name,
|
|
473
502
|
title,
|
|
474
503
|
disabled = false,
|
|
@@ -478,13 +507,11 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
|
|
|
478
507
|
registry,
|
|
479
508
|
onBlur,
|
|
480
509
|
onFocus,
|
|
481
|
-
idPrefix,
|
|
482
|
-
idSeparator = '_',
|
|
483
510
|
rawErrors,
|
|
484
511
|
} = this.props;
|
|
485
512
|
const { keyedFormData } = this.state;
|
|
486
513
|
const fieldTitle = schema.title || title || name;
|
|
487
|
-
const { schemaUtils, formContext } = registry;
|
|
514
|
+
const { schemaUtils, formContext, globalFormOptions } = registry;
|
|
488
515
|
const uiOptions = getUiOptions<T[], S, F>(uiSchema);
|
|
489
516
|
const _schemaItems: S = isObject(schema.items) ? (schema.items as S) : ({} as S);
|
|
490
517
|
const itemsSchema: S = schemaUtils.retrieveSchema(_schemaItems);
|
|
@@ -498,8 +525,11 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
|
|
|
498
525
|
const itemCast = item as unknown as T[];
|
|
499
526
|
const itemSchema = schemaUtils.retrieveSchema(_schemaItems, itemCast);
|
|
500
527
|
const itemErrorSchema = errorSchema ? (errorSchema[index] as ErrorSchema<T[]>) : undefined;
|
|
501
|
-
const
|
|
502
|
-
|
|
528
|
+
const itemFieldPathId = toFieldPathId(index, globalFormOptions, fieldPathId);
|
|
529
|
+
|
|
530
|
+
// Compute the item UI schema using the helper method
|
|
531
|
+
const itemUiSchema = this.computeItemUiSchema(uiSchema, item, index, formContext);
|
|
532
|
+
|
|
503
533
|
return this.renderArrayFieldItem({
|
|
504
534
|
key,
|
|
505
535
|
index,
|
|
@@ -509,10 +539,10 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
|
|
|
509
539
|
canMoveUp: index > 0,
|
|
510
540
|
canMoveDown: index < formData.length - 1,
|
|
511
541
|
itemSchema,
|
|
512
|
-
|
|
542
|
+
itemFieldPathId,
|
|
513
543
|
itemErrorSchema,
|
|
514
544
|
itemData: itemCast,
|
|
515
|
-
itemUiSchema
|
|
545
|
+
itemUiSchema,
|
|
516
546
|
autofocus: autofocus && index === 0,
|
|
517
547
|
onBlur,
|
|
518
548
|
onFocus,
|
|
@@ -522,14 +552,13 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
|
|
|
522
552
|
}),
|
|
523
553
|
className: `rjsf-field rjsf-field-array rjsf-field-array-of-${itemsSchema.type}`,
|
|
524
554
|
disabled,
|
|
525
|
-
|
|
555
|
+
fieldPathId,
|
|
526
556
|
uiSchema,
|
|
527
557
|
onAddClick: this.onAddClick,
|
|
528
558
|
readonly,
|
|
529
559
|
required,
|
|
530
560
|
schema,
|
|
531
561
|
title: fieldTitle,
|
|
532
|
-
formContext,
|
|
533
562
|
formData,
|
|
534
563
|
rawErrors,
|
|
535
564
|
registry,
|
|
@@ -544,7 +573,7 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
|
|
|
544
573
|
renderCustomWidget() {
|
|
545
574
|
const {
|
|
546
575
|
schema,
|
|
547
|
-
|
|
576
|
+
fieldPathId,
|
|
548
577
|
uiSchema,
|
|
549
578
|
disabled = false,
|
|
550
579
|
readonly = false,
|
|
@@ -566,7 +595,7 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
|
|
|
566
595
|
const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions);
|
|
567
596
|
return (
|
|
568
597
|
<Widget
|
|
569
|
-
id={
|
|
598
|
+
id={fieldPathId.$id}
|
|
570
599
|
name={name}
|
|
571
600
|
multiple
|
|
572
601
|
onChange={this.onSelectChange}
|
|
@@ -596,7 +625,7 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
|
|
|
596
625
|
renderMultiSelect() {
|
|
597
626
|
const {
|
|
598
627
|
schema,
|
|
599
|
-
|
|
628
|
+
fieldPathId,
|
|
600
629
|
uiSchema,
|
|
601
630
|
formData: items = [],
|
|
602
631
|
disabled = false,
|
|
@@ -619,7 +648,7 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
|
|
|
619
648
|
const displayLabel = schemaUtils.getDisplayLabel(schema, uiSchema, globalUiOptions);
|
|
620
649
|
return (
|
|
621
650
|
<Widget
|
|
622
|
-
id={
|
|
651
|
+
id={fieldPathId.$id}
|
|
623
652
|
name={name}
|
|
624
653
|
multiple
|
|
625
654
|
onChange={this.onSelectChange}
|
|
@@ -649,7 +678,7 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
|
|
|
649
678
|
const {
|
|
650
679
|
schema,
|
|
651
680
|
uiSchema,
|
|
652
|
-
|
|
681
|
+
fieldPathId,
|
|
653
682
|
name,
|
|
654
683
|
disabled = false,
|
|
655
684
|
readonly = false,
|
|
@@ -669,7 +698,7 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
|
|
|
669
698
|
return (
|
|
670
699
|
<Widget
|
|
671
700
|
options={options}
|
|
672
|
-
id={
|
|
701
|
+
id={fieldPathId.$id}
|
|
673
702
|
name={name}
|
|
674
703
|
multiple
|
|
675
704
|
onChange={this.onSelectChange}
|
|
@@ -699,9 +728,7 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
|
|
|
699
728
|
uiSchema = {},
|
|
700
729
|
formData = [],
|
|
701
730
|
errorSchema,
|
|
702
|
-
|
|
703
|
-
idSeparator = '_',
|
|
704
|
-
idSchema,
|
|
731
|
+
fieldPathId,
|
|
705
732
|
name,
|
|
706
733
|
title,
|
|
707
734
|
disabled = false,
|
|
@@ -717,7 +744,7 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
|
|
|
717
744
|
let { formData: items = [] } = this.props;
|
|
718
745
|
const fieldTitle = schema.title || title || name;
|
|
719
746
|
const uiOptions = getUiOptions<T[], S, F>(uiSchema);
|
|
720
|
-
const { schemaUtils, formContext } = registry;
|
|
747
|
+
const { schemaUtils, formContext, globalFormOptions } = registry;
|
|
721
748
|
const _schemaItems: S[] = isObject(schema.items) ? (schema.items as S[]) : ([] as S[]);
|
|
722
749
|
const itemSchemas = _schemaItems.map((item: S, index: number) =>
|
|
723
750
|
schemaUtils.retrieveSchema(item, formData[index] as unknown as T[]),
|
|
@@ -738,7 +765,7 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
|
|
|
738
765
|
canAdd,
|
|
739
766
|
className: 'rjsf-field rjsf-field-array rjsf-field-array-fixed-items',
|
|
740
767
|
disabled,
|
|
741
|
-
|
|
768
|
+
fieldPathId,
|
|
742
769
|
formData,
|
|
743
770
|
items: keyedFormData.map((keyedItem, index) => {
|
|
744
771
|
const { key, item } = keyedItem;
|
|
@@ -749,13 +776,21 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
|
|
|
749
776
|
(additional && isObject(schema.additionalItems)
|
|
750
777
|
? schemaUtils.retrieveSchema(schema.additionalItems as S, itemCast)
|
|
751
778
|
: itemSchemas[index]) || {};
|
|
752
|
-
const
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
779
|
+
const itemFieldPathId = toFieldPathId(index, globalFormOptions, fieldPathId);
|
|
780
|
+
// Compute the item UI schema - handle both static and dynamic cases
|
|
781
|
+
let itemUiSchema: UiSchema<T[], S, F> | undefined;
|
|
782
|
+
if (additional) {
|
|
783
|
+
// For additional items, use additionalItems uiSchema
|
|
784
|
+
itemUiSchema = uiSchema.additionalItems as UiSchema<T[], S, F>;
|
|
785
|
+
} else {
|
|
786
|
+
// For fixed items, uiSchema.items can be an array, a function, or a single object
|
|
787
|
+
if (Array.isArray(uiSchema.items)) {
|
|
788
|
+
itemUiSchema = uiSchema.items[index] as UiSchema<T[], S, F>;
|
|
789
|
+
} else {
|
|
790
|
+
// Use the helper method for function or static object cases
|
|
791
|
+
itemUiSchema = this.computeItemUiSchema(uiSchema, item, index, formContext);
|
|
792
|
+
}
|
|
793
|
+
}
|
|
759
794
|
const itemErrorSchema = errorSchema ? (errorSchema[index] as ErrorSchema<T[]>) : undefined;
|
|
760
795
|
|
|
761
796
|
return this.renderArrayFieldItem({
|
|
@@ -770,7 +805,7 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
|
|
|
770
805
|
itemSchema,
|
|
771
806
|
itemData: itemCast,
|
|
772
807
|
itemUiSchema,
|
|
773
|
-
|
|
808
|
+
itemFieldPathId,
|
|
774
809
|
itemErrorSchema,
|
|
775
810
|
autofocus: autofocus && index === 0,
|
|
776
811
|
onBlur,
|
|
@@ -786,7 +821,6 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
|
|
|
786
821
|
schema,
|
|
787
822
|
uiSchema,
|
|
788
823
|
title: fieldTitle,
|
|
789
|
-
formContext,
|
|
790
824
|
errorSchema,
|
|
791
825
|
rawErrors,
|
|
792
826
|
};
|
|
@@ -811,8 +845,8 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
|
|
|
811
845
|
canMoveDown: boolean;
|
|
812
846
|
itemSchema: S;
|
|
813
847
|
itemData: T[];
|
|
814
|
-
itemUiSchema: UiSchema<T[], S, F
|
|
815
|
-
|
|
848
|
+
itemUiSchema: UiSchema<T[], S, F> | undefined;
|
|
849
|
+
itemFieldPathId: FieldPathId;
|
|
816
850
|
itemErrorSchema?: ErrorSchema<T[]>;
|
|
817
851
|
autofocus?: boolean;
|
|
818
852
|
onBlur: FieldProps<T[], S, F>['onBlur'];
|
|
@@ -831,7 +865,7 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
|
|
|
831
865
|
itemSchema,
|
|
832
866
|
itemData,
|
|
833
867
|
itemUiSchema,
|
|
834
|
-
|
|
868
|
+
itemFieldPathId,
|
|
835
869
|
itemErrorSchema,
|
|
836
870
|
autofocus,
|
|
837
871
|
onBlur,
|
|
@@ -840,7 +874,7 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
|
|
|
840
874
|
totalItems,
|
|
841
875
|
title,
|
|
842
876
|
} = props;
|
|
843
|
-
const { disabled, hideError,
|
|
877
|
+
const { disabled, hideError, readonly, uiSchema, registry, formContext } = this.props;
|
|
844
878
|
const {
|
|
845
879
|
fields: { ArraySchemaField, SchemaField },
|
|
846
880
|
globalUiOptions,
|
|
@@ -867,9 +901,7 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
|
|
|
867
901
|
formData={itemData}
|
|
868
902
|
formContext={formContext}
|
|
869
903
|
errorSchema={itemErrorSchema}
|
|
870
|
-
|
|
871
|
-
idSeparator={idSeparator}
|
|
872
|
-
idSchema={itemIdSchema}
|
|
904
|
+
fieldPathId={itemFieldPathId}
|
|
873
905
|
required={this.isItemRequired(itemSchema)}
|
|
874
906
|
onChange={this.onChangeForIndex(index)}
|
|
875
907
|
onBlur={onBlur}
|
|
@@ -883,7 +915,7 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
|
|
|
883
915
|
/>
|
|
884
916
|
),
|
|
885
917
|
buttonsProps: {
|
|
886
|
-
|
|
918
|
+
fieldPathId: itemFieldPathId,
|
|
887
919
|
disabled: disabled,
|
|
888
920
|
readonly: readonly,
|
|
889
921
|
canAdd,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
1
2
|
import {
|
|
2
3
|
getWidget,
|
|
3
4
|
getUiOptions,
|
|
@@ -5,6 +6,7 @@ import {
|
|
|
5
6
|
FieldProps,
|
|
6
7
|
FormContextType,
|
|
7
8
|
EnumOptionsType,
|
|
9
|
+
ErrorSchema,
|
|
8
10
|
RJSFSchema,
|
|
9
11
|
StrictRJSFSchema,
|
|
10
12
|
TranslatableString,
|
|
@@ -23,7 +25,7 @@ function BooleanField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extend
|
|
|
23
25
|
schema,
|
|
24
26
|
name,
|
|
25
27
|
uiSchema,
|
|
26
|
-
|
|
28
|
+
fieldPathId,
|
|
27
29
|
formData,
|
|
28
30
|
registry,
|
|
29
31
|
required,
|
|
@@ -86,15 +88,22 @@ function BooleanField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extend
|
|
|
86
88
|
enumOptions = optionsList<T, S, F>({ enum: enums } as S, uiSchema);
|
|
87
89
|
}
|
|
88
90
|
}
|
|
91
|
+
const onWidgetChange = useCallback(
|
|
92
|
+
(value: T | undefined, errorSchema?: ErrorSchema, id?: string) => {
|
|
93
|
+
// Boolean field change passes an empty path array to the parent field which adds the appropriate path
|
|
94
|
+
return onChange(value, fieldPathId.path, errorSchema, id);
|
|
95
|
+
},
|
|
96
|
+
[onChange, fieldPathId],
|
|
97
|
+
);
|
|
89
98
|
|
|
90
99
|
return (
|
|
91
100
|
<Widget
|
|
92
101
|
options={{ ...options, enumOptions }}
|
|
93
102
|
schema={schema}
|
|
94
103
|
uiSchema={uiSchema}
|
|
95
|
-
id={
|
|
104
|
+
id={fieldPathId.$id}
|
|
96
105
|
name={name}
|
|
97
|
-
onChange={
|
|
106
|
+
onChange={onWidgetChange}
|
|
98
107
|
onFocus={onFocus}
|
|
99
108
|
onBlur={onBlur}
|
|
100
109
|
label={label}
|