Skip to content

async validation resets anyOf fields with no way to avoid it #4571

@TheOneTheOnlyJJ

Description

@TheOneTheOnlyJJ

Prerequisites

What theme are you using?

mui

Version

5.24.7

Current Behavior

This problem is caused by anyOf fields being reset when the Form's onSubmit handler is executed.

This causes both the anyOf user selection option to be reset to the default first one, and any input data from the selected anyOf subschema to be lost.

This is very annoying, as the async validation error may be caused by some value outside the anyOf subschema altogether.

I have not found a way to avoid this problem.

Expected Behavior

When async validation is performed (in the onSubmit handler), any anyOf field and subschema input should be retained.

Maybe a new prop could be introduced that would allow the Form to retain its input data even after the onSubmit handler ran?

Or, alternatively...

Maybe the onSubmit handler could return a boolean that determines the clearing of the Form's input data. This way, failing additional async validation could allow the developer to return a boolean signaling that the current input data should be kept in the form.

Steps To Reproduce

No response

Environment

Irrelevant for this issue

Anything else?

If anyone is aware of a way to avoid this anyOf field value reset issue in this case, please share it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugneeds triageInitial label given, to be assigned correct labels and assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions