Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation errors are not updated after config and field change #56

Open
meehaws opened this issue Jun 7, 2019 · 2 comments
Open

Validation errors are not updated after config and field change #56

meehaws opened this issue Jun 7, 2019 · 2 comments

Comments

@meehaws
Copy link

meehaws commented Jun 7, 2019

Hi,

I have a dynamic content of my form, which is rendered based on type (it is provided from some drop down). Form inputs will change based on that type and so will do config.

What I observe after changing type to a different one, is that inside Validation component values:

  • fields will change to the new once
  • config will change to the new values
  • errors will stay as they were before changing type
<ValidatorsProvider validators={allValidators}>
                                <Form onSubmit={onSubmit} id={'someId'} className={classes.content}>
                                    <Validation config={selectConfigBasedOntype(type))}
                                                initialValues={defaults}>
                                        {generateDynamicFieldsBasedOnType}
                                    </Validation>
                                </Form>
                            </ValidatorsProvider>
@serenata-keith-mifsud
Copy link
Contributor

I just encountered the same issue, and managed to solve it by providing a different key to Validation. The issue is mainly that config is registered with Form on Validation.componentDidMount. By providing the different key, we're forcing react to unmount the current Validation, and mounting a new one

@ArrayKnight
Copy link
Contributor

ArrayKnight commented Jun 13, 2019

@meehaws You're correct, the config object is only utilized once at registration. But as @serenata-keith-mifsud suggested, a key to force a unregister/register to occur will reset those fields.

We could potentially add a feature to allow for the config prop to be updated and to handle this. However, it could potentially run into issue of wiping out form data unintentionally. If you want to create a PR, we'd be happy to review it. Just be sure to thoroughly test it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants