Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ it according to semantic versioning. For example, if your PR adds a breaking cha
should change the heading of the (upcoming) version to include a major version bump.

-->
# 6.0.0-beta.19

## @rjsf/core

- Updated `Form` to fix live validation in `getStateFromProps()` broken by an optimization, fixing [#4782](https://github.com/rjsf-team/react-jsonschema-form/issues/4782)

## @rjsf/utils

- Updated `resolveSchema()` to pass the `experimental_customMergeAllOf` options properly to `resolveReference()` and `resolveDependencies()` called within it

# 6.0.0-beta.18

## @rjsf/chakra-ui
Expand Down
9 changes: 6 additions & 3 deletions packages/core/src/components/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ export default class Form<
* @param retrievedSchema - An expanded schema, if not provided, it will be retrieved from the `schema` and `formData`.
* @param isSchemaChanged - A flag indicating whether the schema has changed.
* @param formDataChangedFields - The changed fields of `formData`
* @param skipLiveValidate - Optional flag, if true, means that we are not running live validation
* @returns - The new state for the `Form`
*/
getStateFromProps(
Expand All @@ -432,7 +433,7 @@ export default class Form<
const uiSchema: UiSchema<T, S, F> = ('uiSchema' in props ? props.uiSchema! : this.props.uiSchema!) || {};
const edit = typeof inputFormData !== 'undefined';
const liveValidate = 'liveValidate' in props ? props.liveValidate : this.props.liveValidate;
const mustValidate = edit && !props.noValidate && liveValidate && !skipLiveValidate;
const mustValidate = edit && !props.noValidate && liveValidate;
const experimental_defaultFormStateBehavior =
'experimental_defaultFormStateBehavior' in props
? props.experimental_defaultFormStateBehavior
Expand Down Expand Up @@ -484,7 +485,8 @@ export default class Form<
let errorSchema: ErrorSchema<T> | undefined;
let schemaValidationErrors: RJSFValidationError[] = state.schemaValidationErrors;
let schemaValidationErrorSchema: ErrorSchema<T> = state.schemaValidationErrorSchema;
if (mustValidate) {
// If we are skipping live validate, it means that the state has already been updated with live validation errors
if (mustValidate && !skipLiveValidate) {
const schemaValidation = this.validate(formData, rootSchema, schemaUtils, _retrievedSchema);
errors = schemaValidation.errors;
// If retrievedSchema is undefined which means the schema or formData has changed, we do not merge state.
Expand All @@ -504,7 +506,8 @@ export default class Form<
const currentErrors = getCurrentErrors();
errors = currentErrors.errors;
errorSchema = currentErrors.errorSchema;
if (formDataChangedFields.length > 0) {
// We only update the error schema for changed fields if mustValidate is false
if (formDataChangedFields.length > 0 && !mustValidate) {
const newErrorSchema = formDataChangedFields.reduce(
(acc, key) => {
acc[key] = undefined;
Expand Down
3 changes: 2 additions & 1 deletion packages/playground/src/components/Playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ export default function Playground({ themes, validators }: PlaygroundProps) {
}, [onThemeSelected, load, loaded, setShowForm, theme, themes]);

const onFormDataChange = useCallback(
({ formData }: IChangeEvent, id?: string) => {
(event: IChangeEvent, id?: string) => {
const { formData } = event;
if (id) {
console.log('Field changed, id: ', id);
}
Expand Down