@rjsf/core 5.18.5 → 5.19.0
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 +79 -69
- package/dist/index.esm.js +80 -66
- package/dist/index.esm.js.map +2 -2
- package/dist/index.js +79 -65
- package/dist/index.js.map +2 -2
- package/lib/components/Form.d.ts +16 -2
- package/lib/components/Form.js +77 -56
- package/lib/components/Form.js.map +1 -1
- package/lib/components/fields/SchemaField.js +3 -3
- package/lib/components/fields/SchemaField.js.map +1 -1
- package/lib/components/widgets/AltDateWidget.js +2 -9
- package/lib/components/widgets/AltDateWidget.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -6
- package/src/components/Form.tsx +38 -19
- package/src/components/fields/SchemaField.tsx +1 -1
- package/src/components/widgets/AltDateWidget.tsx +2 -10
package/dist/index.js
CHANGED
|
@@ -1505,7 +1505,7 @@ function SchemaFieldRender(props) {
|
|
|
1505
1505
|
);
|
|
1506
1506
|
const FieldComponent = getFieldComponent(schema, uiOptions, idSchema, registry);
|
|
1507
1507
|
const disabled = Boolean(uiOptions.disabled ?? props.disabled);
|
|
1508
|
-
const readonly = Boolean(uiOptions.readonly ?? props.readonly
|
|
1508
|
+
const readonly = Boolean(uiOptions.readonly ?? (props.readonly || props.schema.readOnly || schema.readOnly));
|
|
1509
1509
|
const uiSchemaHideError = uiOptions.hideError;
|
|
1510
1510
|
const hideError = uiSchemaHideError === void 0 ? props.hideError : Boolean(uiSchemaHideError);
|
|
1511
1511
|
const autofocus = Boolean(uiOptions.autofocus ?? props.autofocus);
|
|
@@ -2462,13 +2462,6 @@ var templates_default = templates;
|
|
|
2462
2462
|
var import_react8 = require("react");
|
|
2463
2463
|
var import_utils22 = require("@rjsf/utils");
|
|
2464
2464
|
var import_jsx_runtime26 = require("react/jsx-runtime");
|
|
2465
|
-
function rangeOptions(start, stop) {
|
|
2466
|
-
const options = [];
|
|
2467
|
-
for (let i = start; i <= stop; i++) {
|
|
2468
|
-
options.push({ value: i, label: (0, import_utils22.pad)(i, 2) });
|
|
2469
|
-
}
|
|
2470
|
-
return options;
|
|
2471
|
-
}
|
|
2472
2465
|
function readyForChange(state) {
|
|
2473
2466
|
return Object.values(state).every((value) => value !== -1);
|
|
2474
2467
|
}
|
|
@@ -2495,7 +2488,7 @@ function DateElement({
|
|
|
2495
2488
|
id,
|
|
2496
2489
|
name,
|
|
2497
2490
|
className: "form-control",
|
|
2498
|
-
options: { enumOptions:
|
|
2491
|
+
options: { enumOptions: (0, import_utils22.dateRangeOptions)(range[0], range[1]) },
|
|
2499
2492
|
placeholder: type,
|
|
2500
2493
|
value,
|
|
2501
2494
|
disabled,
|
|
@@ -3285,9 +3278,22 @@ var Form = class extends import_react17.Component {
|
|
|
3285
3278
|
};
|
|
3286
3279
|
return getAllPaths(pathSchema);
|
|
3287
3280
|
};
|
|
3281
|
+
/** Returns the `formData` after filtering to remove any extra data not in a form field
|
|
3282
|
+
*
|
|
3283
|
+
* @param formData - The data for the `Form`
|
|
3284
|
+
* @returns The `formData` after omitting extra data
|
|
3285
|
+
*/
|
|
3286
|
+
this.omitExtraData = (formData) => {
|
|
3287
|
+
const { schema, schemaUtils } = this.state;
|
|
3288
|
+
const retrievedSchema = schemaUtils.retrieveSchema(schema, formData);
|
|
3289
|
+
const pathSchema = schemaUtils.toPathSchema(retrievedSchema, "", formData);
|
|
3290
|
+
const fieldNames = this.getFieldNames(pathSchema, formData);
|
|
3291
|
+
const newFormData = this.getUsedFormData(formData, fieldNames);
|
|
3292
|
+
return newFormData;
|
|
3293
|
+
};
|
|
3288
3294
|
/** Function to handle changes made to a field in the `Form`. This handler receives an entirely new copy of the
|
|
3289
3295
|
* `formData` along with a new `ErrorSchema`. It will first update the `formData` with any missing default fields and
|
|
3290
|
-
* then, if `omitExtraData` and `liveOmit` are turned on, the `formData` will be
|
|
3296
|
+
* then, if `omitExtraData` and `liveOmit` are turned on, the `formData` will be filtered to remove any extra data not
|
|
3291
3297
|
* in a form field. Then, the resulting formData will be validated if required. The state will be updated with the new
|
|
3292
3298
|
* updated (potentially filtered) `formData`, any errors that resulted from validation. Finally the `onChange`
|
|
3293
3299
|
* callback will be called if specified with the updated state.
|
|
@@ -3308,10 +3314,7 @@ var Form = class extends import_react17.Component {
|
|
|
3308
3314
|
let newFormData = formData;
|
|
3309
3315
|
let _retrievedSchema;
|
|
3310
3316
|
if (omitExtraData === true && liveOmit === true) {
|
|
3311
|
-
|
|
3312
|
-
const pathSchema = schemaUtils.toPathSchema(_retrievedSchema, "", formData);
|
|
3313
|
-
const fieldNames = this.getFieldNames(pathSchema, formData);
|
|
3314
|
-
newFormData = this.getUsedFormData(formData, fieldNames);
|
|
3317
|
+
newFormData = this.omitExtraData(formData);
|
|
3315
3318
|
state = {
|
|
3316
3319
|
formData: newFormData
|
|
3317
3320
|
};
|
|
@@ -3406,14 +3409,10 @@ var Form = class extends import_react17.Component {
|
|
|
3406
3409
|
event.persist();
|
|
3407
3410
|
const { omitExtraData, extraErrors, noValidate, onSubmit } = this.props;
|
|
3408
3411
|
let { formData: newFormData } = this.state;
|
|
3409
|
-
const { schema, schemaUtils } = this.state;
|
|
3410
3412
|
if (omitExtraData === true) {
|
|
3411
|
-
|
|
3412
|
-
const pathSchema = schemaUtils.toPathSchema(retrievedSchema, "", newFormData);
|
|
3413
|
-
const fieldNames = this.getFieldNames(pathSchema, newFormData);
|
|
3414
|
-
newFormData = this.getUsedFormData(newFormData, fieldNames);
|
|
3413
|
+
newFormData = this.omitExtraData(newFormData);
|
|
3415
3414
|
}
|
|
3416
|
-
if (noValidate || this.
|
|
3415
|
+
if (noValidate || this.validateFormWithFormData(newFormData)) {
|
|
3417
3416
|
const errorSchema = extraErrors || {};
|
|
3418
3417
|
const errors = extraErrors ? (0, import_utils39.toErrorList)(extraErrors) : [];
|
|
3419
3418
|
this.setState(
|
|
@@ -3443,6 +3442,59 @@ var Form = class extends import_react17.Component {
|
|
|
3443
3442
|
this.formElement.current.requestSubmit();
|
|
3444
3443
|
}
|
|
3445
3444
|
};
|
|
3445
|
+
/** Validates the form using the given `formData`. For use on form submission or on programmatic validation.
|
|
3446
|
+
* If `onError` is provided, then it will be called with the list of errors.
|
|
3447
|
+
*
|
|
3448
|
+
* @param formData - The form data to validate
|
|
3449
|
+
* @returns - True if the form is valid, false otherwise.
|
|
3450
|
+
*/
|
|
3451
|
+
this.validateFormWithFormData = (formData) => {
|
|
3452
|
+
const { extraErrors, extraErrorsBlockSubmit, focusOnFirstError, onError } = this.props;
|
|
3453
|
+
const { errors: prevErrors } = this.state;
|
|
3454
|
+
const schemaValidation = this.validate(formData);
|
|
3455
|
+
let errors = schemaValidation.errors;
|
|
3456
|
+
let errorSchema = schemaValidation.errorSchema;
|
|
3457
|
+
const schemaValidationErrors = errors;
|
|
3458
|
+
const schemaValidationErrorSchema = errorSchema;
|
|
3459
|
+
const hasError = errors.length > 0 || extraErrors && extraErrorsBlockSubmit;
|
|
3460
|
+
if (hasError) {
|
|
3461
|
+
if (extraErrors) {
|
|
3462
|
+
const merged = (0, import_utils39.validationDataMerge)(schemaValidation, extraErrors);
|
|
3463
|
+
errorSchema = merged.errorSchema;
|
|
3464
|
+
errors = merged.errors;
|
|
3465
|
+
}
|
|
3466
|
+
if (focusOnFirstError) {
|
|
3467
|
+
if (typeof focusOnFirstError === "function") {
|
|
3468
|
+
focusOnFirstError(errors[0]);
|
|
3469
|
+
} else {
|
|
3470
|
+
this.focusOnError(errors[0]);
|
|
3471
|
+
}
|
|
3472
|
+
}
|
|
3473
|
+
this.setState(
|
|
3474
|
+
{
|
|
3475
|
+
errors,
|
|
3476
|
+
errorSchema,
|
|
3477
|
+
schemaValidationErrors,
|
|
3478
|
+
schemaValidationErrorSchema
|
|
3479
|
+
},
|
|
3480
|
+
() => {
|
|
3481
|
+
if (onError) {
|
|
3482
|
+
onError(errors);
|
|
3483
|
+
} else {
|
|
3484
|
+
console.error("Form validation failed", errors);
|
|
3485
|
+
}
|
|
3486
|
+
}
|
|
3487
|
+
);
|
|
3488
|
+
} else if (prevErrors.length > 0) {
|
|
3489
|
+
this.setState({
|
|
3490
|
+
errors: [],
|
|
3491
|
+
errorSchema: {},
|
|
3492
|
+
schemaValidationErrors: [],
|
|
3493
|
+
schemaValidationErrorSchema: {}
|
|
3494
|
+
});
|
|
3495
|
+
}
|
|
3496
|
+
return !hasError;
|
|
3497
|
+
};
|
|
3446
3498
|
if (!props.validator) {
|
|
3447
3499
|
throw new Error("A validator is required for Form functionality to work");
|
|
3448
3500
|
}
|
|
@@ -3686,57 +3738,19 @@ var Form = class extends import_react17.Component {
|
|
|
3686
3738
|
field.focus();
|
|
3687
3739
|
}
|
|
3688
3740
|
}
|
|
3689
|
-
/** Programmatically validate the form.
|
|
3741
|
+
/** Programmatically validate the form. If `omitExtraData` is true, the `formData` will first be filtered to remove
|
|
3742
|
+
* any extra data not in a form field. If `onError` is provided, then it will be called with the list of errors the
|
|
3690
3743
|
* same way as would happen on form submission.
|
|
3691
3744
|
*
|
|
3692
3745
|
* @returns - True if the form is valid, false otherwise.
|
|
3693
3746
|
*/
|
|
3694
3747
|
validateForm() {
|
|
3695
|
-
const {
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
let errorSchema = schemaValidation.errorSchema;
|
|
3700
|
-
const schemaValidationErrors = errors;
|
|
3701
|
-
const schemaValidationErrorSchema = errorSchema;
|
|
3702
|
-
const hasError = errors.length > 0 || extraErrors && extraErrorsBlockSubmit;
|
|
3703
|
-
if (hasError) {
|
|
3704
|
-
if (extraErrors) {
|
|
3705
|
-
const merged = (0, import_utils39.validationDataMerge)(schemaValidation, extraErrors);
|
|
3706
|
-
errorSchema = merged.errorSchema;
|
|
3707
|
-
errors = merged.errors;
|
|
3708
|
-
}
|
|
3709
|
-
if (focusOnFirstError) {
|
|
3710
|
-
if (typeof focusOnFirstError === "function") {
|
|
3711
|
-
focusOnFirstError(errors[0]);
|
|
3712
|
-
} else {
|
|
3713
|
-
this.focusOnError(errors[0]);
|
|
3714
|
-
}
|
|
3715
|
-
}
|
|
3716
|
-
this.setState(
|
|
3717
|
-
{
|
|
3718
|
-
errors,
|
|
3719
|
-
errorSchema,
|
|
3720
|
-
schemaValidationErrors,
|
|
3721
|
-
schemaValidationErrorSchema
|
|
3722
|
-
},
|
|
3723
|
-
() => {
|
|
3724
|
-
if (onError) {
|
|
3725
|
-
onError(errors);
|
|
3726
|
-
} else {
|
|
3727
|
-
console.error("Form validation failed", errors);
|
|
3728
|
-
}
|
|
3729
|
-
}
|
|
3730
|
-
);
|
|
3731
|
-
} else if (prevErrors.length > 0) {
|
|
3732
|
-
this.setState({
|
|
3733
|
-
errors: [],
|
|
3734
|
-
errorSchema: {},
|
|
3735
|
-
schemaValidationErrors: [],
|
|
3736
|
-
schemaValidationErrorSchema: {}
|
|
3737
|
-
});
|
|
3748
|
+
const { omitExtraData } = this.props;
|
|
3749
|
+
let { formData: newFormData } = this.state;
|
|
3750
|
+
if (omitExtraData === true) {
|
|
3751
|
+
newFormData = this.omitExtraData(newFormData);
|
|
3738
3752
|
}
|
|
3739
|
-
return
|
|
3753
|
+
return this.validateFormWithFormData(newFormData);
|
|
3740
3754
|
}
|
|
3741
3755
|
/** Renders the `Form` fields inside the <form> | `tagName` or `_internalFormWrapper`, rendering any errors if
|
|
3742
3756
|
* needed along with the submit button or any children of the form.
|