@rjsf/core 5.14.1 → 5.14.3
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 +22 -13
- package/dist/index.esm.js +22 -13
- package/dist/index.esm.js.map +2 -2
- package/dist/index.js +22 -13
- package/dist/index.js.map +2 -2
- package/lib/components/Form.d.ts +4 -2
- package/lib/components/Form.js +32 -20
- package/lib/components/Form.js.map +1 -1
- package/lib/components/fields/ArrayField.js +10 -8
- package/lib/components/fields/ArrayField.js.map +1 -1
- package/lib/components/fields/BooleanField.js +7 -5
- package/lib/components/fields/BooleanField.js.map +1 -1
- package/lib/components/fields/MultiSchemaField.js +2 -3
- package/lib/components/fields/MultiSchemaField.js.map +1 -1
- package/lib/components/fields/NumberField.js +1 -1
- package/lib/components/fields/NumberField.js.map +1 -1
- package/lib/components/fields/ObjectField.js +16 -8
- package/lib/components/fields/ObjectField.js.map +1 -1
- package/lib/components/fields/SchemaField.js +4 -5
- package/lib/components/fields/SchemaField.js.map +1 -1
- package/lib/components/fields/StringField.js +2 -3
- package/lib/components/fields/StringField.js.map +1 -1
- package/lib/components/templates/ArrayFieldItemTemplate.js +2 -2
- package/lib/components/templates/ArrayFieldItemTemplate.js.map +1 -1
- package/lib/components/templates/ArrayFieldTemplate.js +2 -6
- package/lib/components/templates/ArrayFieldTemplate.js.map +1 -1
- package/lib/components/templates/BaseInputTemplate.js +8 -6
- package/lib/components/templates/BaseInputTemplate.js.map +1 -1
- package/lib/components/templates/ButtonTemplates/AddButton.js +1 -1
- package/lib/components/templates/ButtonTemplates/AddButton.js.map +1 -1
- package/lib/components/templates/ButtonTemplates/IconButton.js +6 -7
- package/lib/components/templates/ButtonTemplates/IconButton.js.map +1 -1
- package/lib/components/templates/ButtonTemplates/SubmitButton.js +1 -1
- package/lib/components/templates/ButtonTemplates/SubmitButton.js.map +1 -1
- package/lib/components/templates/DescriptionField.js +2 -2
- package/lib/components/templates/DescriptionField.js.map +1 -1
- package/lib/components/templates/ErrorList.js +3 -3
- package/lib/components/templates/ErrorList.js.map +1 -1
- package/lib/components/templates/FieldErrorTemplate.js +3 -3
- package/lib/components/templates/FieldErrorTemplate.js.map +1 -1
- package/lib/components/templates/FieldHelpTemplate.js +2 -2
- package/lib/components/templates/FieldHelpTemplate.js.map +1 -1
- package/lib/components/templates/FieldTemplate/FieldTemplate.js +2 -2
- package/lib/components/templates/FieldTemplate/FieldTemplate.js.map +1 -1
- package/lib/components/templates/FieldTemplate/Label.js +1 -1
- package/lib/components/templates/FieldTemplate/Label.js.map +1 -1
- package/lib/components/templates/ObjectFieldTemplate.js +1 -1
- package/lib/components/templates/ObjectFieldTemplate.js.map +1 -1
- package/lib/components/templates/TitleField.js +1 -1
- package/lib/components/templates/TitleField.js.map +1 -1
- package/lib/components/templates/UnsupportedField.js +1 -1
- package/lib/components/templates/UnsupportedField.js.map +1 -1
- package/lib/components/templates/WrapIfAdditionalTemplate.js +2 -2
- package/lib/components/templates/WrapIfAdditionalTemplate.js.map +1 -1
- package/lib/components/widgets/AltDateTimeWidget.js +2 -4
- package/lib/components/widgets/AltDateTimeWidget.js.map +1 -1
- package/lib/components/widgets/AltDateWidget.js +2 -2
- package/lib/components/widgets/AltDateWidget.js.map +1 -1
- package/lib/components/widgets/CheckboxWidget.js +1 -1
- package/lib/components/widgets/CheckboxWidget.js.map +1 -1
- package/lib/components/widgets/CheckboxesWidget.js +3 -3
- package/lib/components/widgets/CheckboxesWidget.js.map +1 -1
- package/lib/components/widgets/ColorWidget.js +1 -1
- package/lib/components/widgets/ColorWidget.js.map +1 -1
- package/lib/components/widgets/DateTimeWidget.js +1 -1
- package/lib/components/widgets/DateTimeWidget.js.map +1 -1
- package/lib/components/widgets/DateWidget.js +1 -1
- package/lib/components/widgets/DateWidget.js.map +1 -1
- package/lib/components/widgets/EmailWidget.js +1 -1
- package/lib/components/widgets/EmailWidget.js.map +1 -1
- package/lib/components/widgets/FileWidget.js +4 -4
- package/lib/components/widgets/FileWidget.js.map +1 -1
- package/lib/components/widgets/PasswordWidget.js +1 -1
- package/lib/components/widgets/PasswordWidget.js.map +1 -1
- package/lib/components/widgets/RadioWidget.js +3 -3
- package/lib/components/widgets/RadioWidget.js.map +1 -1
- package/lib/components/widgets/RangeWidget.js +1 -1
- package/lib/components/widgets/RangeWidget.js.map +1 -1
- package/lib/components/widgets/SelectWidget.js +3 -3
- package/lib/components/widgets/SelectWidget.js.map +1 -1
- package/lib/components/widgets/TextWidget.js +1 -1
- package/lib/components/widgets/TextWidget.js.map +1 -1
- package/lib/components/widgets/TimeWidget.js +1 -1
- package/lib/components/widgets/TimeWidget.js.map +1 -1
- package/lib/components/widgets/URLWidget.js +1 -1
- package/lib/components/widgets/URLWidget.js.map +1 -1
- package/lib/components/widgets/UpDownWidget.js +1 -1
- package/lib/components/widgets/UpDownWidget.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/withTheme.js +13 -8
- package/lib/withTheme.js.map +1 -1
- package/package.json +6 -6
- package/src/components/Form.tsx +26 -12
package/src/components/Form.tsx
CHANGED
|
@@ -238,6 +238,9 @@ export interface FormState<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
|
|
|
238
238
|
* `extraErrors`
|
|
239
239
|
*/
|
|
240
240
|
schemaValidationErrorSchema: ErrorSchema<T>;
|
|
241
|
+
// Private
|
|
242
|
+
/** @description result of schemaUtils.retrieveSchema(schema, formData). This a memoized value to avoid re calculate at internal functions (getStateFromProps, onChange) */
|
|
243
|
+
retrievedSchema: S;
|
|
241
244
|
}
|
|
242
245
|
|
|
243
246
|
/** The event data passed when changes have been made to the form, includes everything from the `FormState` except
|
|
@@ -303,7 +306,11 @@ export default class Form<
|
|
|
303
306
|
prevState: FormState<T, S, F>
|
|
304
307
|
): { nextState: FormState<T, S, F>; shouldUpdate: true } | { shouldUpdate: false } {
|
|
305
308
|
if (!deepEquals(this.props, prevProps)) {
|
|
306
|
-
const nextState = this.getStateFromProps(
|
|
309
|
+
const nextState = this.getStateFromProps(
|
|
310
|
+
this.props,
|
|
311
|
+
this.props.formData,
|
|
312
|
+
prevProps.schema !== this.props.schema ? undefined : this.state.retrievedSchema
|
|
313
|
+
);
|
|
307
314
|
const shouldUpdate = !deepEquals(nextState, prevState);
|
|
308
315
|
return { nextState, shouldUpdate };
|
|
309
316
|
}
|
|
@@ -352,7 +359,7 @@ export default class Form<
|
|
|
352
359
|
* @param inputFormData - The new or current data for the `Form`
|
|
353
360
|
* @returns - The new state for the `Form`
|
|
354
361
|
*/
|
|
355
|
-
getStateFromProps(props: FormProps<T, S, F>, inputFormData?: T): FormState<T, S, F> {
|
|
362
|
+
getStateFromProps(props: FormProps<T, S, F>, inputFormData?: T, retrievedSchema?: S): FormState<T, S, F> {
|
|
356
363
|
const state: FormState<T, S, F> = this.state || {};
|
|
357
364
|
const schema = 'schema' in props ? props.schema : this.props.schema;
|
|
358
365
|
const uiSchema: UiSchema<T, S, F> = ('uiSchema' in props ? props.uiSchema! : this.props.uiSchema!) || {};
|
|
@@ -372,7 +379,7 @@ export default class Form<
|
|
|
372
379
|
schemaUtils = createSchemaUtils<T, S, F>(props.validator, rootSchema, experimental_defaultFormStateBehavior);
|
|
373
380
|
}
|
|
374
381
|
const formData: T = schemaUtils.getDefaultFormState(schema, inputFormData) as T;
|
|
375
|
-
const
|
|
382
|
+
const _retrievedSchema = retrievedSchema ?? schemaUtils.retrieveSchema(schema, formData);
|
|
376
383
|
|
|
377
384
|
const getCurrentErrors = (): ValidationData<T> => {
|
|
378
385
|
if (props.noValidate) {
|
|
@@ -394,7 +401,7 @@ export default class Form<
|
|
|
394
401
|
let schemaValidationErrors: RJSFValidationError[] = state.schemaValidationErrors;
|
|
395
402
|
let schemaValidationErrorSchema: ErrorSchema<T> = state.schemaValidationErrorSchema;
|
|
396
403
|
if (mustValidate) {
|
|
397
|
-
const schemaValidation = this.validate(formData, schema, schemaUtils);
|
|
404
|
+
const schemaValidation = this.validate(formData, schema, schemaUtils, _retrievedSchema);
|
|
398
405
|
errors = schemaValidation.errors;
|
|
399
406
|
errorSchema = schemaValidation.errorSchema;
|
|
400
407
|
schemaValidationErrors = errors;
|
|
@@ -410,7 +417,7 @@ export default class Form<
|
|
|
410
417
|
errors = merged.errors;
|
|
411
418
|
}
|
|
412
419
|
const idSchema = schemaUtils.toIdSchema(
|
|
413
|
-
|
|
420
|
+
_retrievedSchema,
|
|
414
421
|
uiSchema['ui:rootFieldId'],
|
|
415
422
|
formData,
|
|
416
423
|
props.idPrefix,
|
|
@@ -427,6 +434,7 @@ export default class Form<
|
|
|
427
434
|
errorSchema,
|
|
428
435
|
schemaValidationErrors,
|
|
429
436
|
schemaValidationErrorSchema,
|
|
437
|
+
retrievedSchema: _retrievedSchema,
|
|
430
438
|
};
|
|
431
439
|
return nextState;
|
|
432
440
|
}
|
|
@@ -451,11 +459,12 @@ export default class Form<
|
|
|
451
459
|
validate(
|
|
452
460
|
formData: T | undefined,
|
|
453
461
|
schema = this.props.schema,
|
|
454
|
-
altSchemaUtils?: SchemaUtilsType<T, S, F
|
|
462
|
+
altSchemaUtils?: SchemaUtilsType<T, S, F>,
|
|
463
|
+
retrievedSchema?: S
|
|
455
464
|
): ValidationData<T> {
|
|
456
465
|
const schemaUtils = altSchemaUtils ? altSchemaUtils : this.state.schemaUtils;
|
|
457
466
|
const { customValidate, transformErrors, uiSchema } = this.props;
|
|
458
|
-
const resolvedSchema = schemaUtils.retrieveSchema(schema, formData);
|
|
467
|
+
const resolvedSchema = retrievedSchema ?? schemaUtils.retrieveSchema(schema, formData);
|
|
459
468
|
return schemaUtils
|
|
460
469
|
.getValidator()
|
|
461
470
|
.validateFormData(formData, resolvedSchema, customValidate, transformErrors, uiSchema);
|
|
@@ -549,9 +558,10 @@ export default class Form<
|
|
|
549
558
|
*/
|
|
550
559
|
onChange = (formData: T | undefined, newErrorSchema?: ErrorSchema<T>, id?: string) => {
|
|
551
560
|
const { extraErrors, omitExtraData, liveOmit, noValidate, liveValidate, onChange } = this.props;
|
|
552
|
-
const { schemaUtils, schema } = this.state;
|
|
561
|
+
const { schemaUtils, schema, retrievedSchema } = this.state;
|
|
562
|
+
|
|
553
563
|
if (isObject(formData) || Array.isArray(formData)) {
|
|
554
|
-
const newState = this.getStateFromProps(this.props, formData);
|
|
564
|
+
const newState = this.getStateFromProps(this.props, formData, retrievedSchema);
|
|
555
565
|
formData = newState.formData;
|
|
556
566
|
}
|
|
557
567
|
|
|
@@ -559,9 +569,10 @@ export default class Form<
|
|
|
559
569
|
let state: Partial<FormState<T, S, F>> = { formData, schema };
|
|
560
570
|
let newFormData = formData;
|
|
561
571
|
|
|
572
|
+
let _retrievedSchema: S | undefined;
|
|
562
573
|
if (omitExtraData === true && liveOmit === true) {
|
|
563
|
-
|
|
564
|
-
const pathSchema = schemaUtils.toPathSchema(
|
|
574
|
+
_retrievedSchema = schemaUtils.retrieveSchema(schema, formData);
|
|
575
|
+
const pathSchema = schemaUtils.toPathSchema(_retrievedSchema, '', formData);
|
|
565
576
|
|
|
566
577
|
const fieldNames = this.getFieldNames(pathSchema, formData);
|
|
567
578
|
|
|
@@ -572,7 +583,7 @@ export default class Form<
|
|
|
572
583
|
}
|
|
573
584
|
|
|
574
585
|
if (mustValidate) {
|
|
575
|
-
const schemaValidation = this.validate(newFormData);
|
|
586
|
+
const schemaValidation = this.validate(newFormData, schema, schemaUtils, retrievedSchema);
|
|
576
587
|
let errors = schemaValidation.errors;
|
|
577
588
|
let errorSchema = schemaValidation.errorSchema;
|
|
578
589
|
const schemaValidationErrors = errors;
|
|
@@ -599,6 +610,9 @@ export default class Form<
|
|
|
599
610
|
errors: toErrorList(errorSchema),
|
|
600
611
|
};
|
|
601
612
|
}
|
|
613
|
+
if (_retrievedSchema) {
|
|
614
|
+
state.retrievedSchema = _retrievedSchema;
|
|
615
|
+
}
|
|
602
616
|
this.setState(state as FormState<T, S, F>, () => onChange && onChange({ ...this.state, ...state }, id));
|
|
603
617
|
};
|
|
604
618
|
|