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

Async validation disables next button on next step #431

Open
rvsia opened this issue Apr 15, 2020 · 3 comments
Open

Async validation disables next button on next step #431

rvsia opened this issue Apr 15, 2020 · 3 comments

Comments

@rvsia
Copy link
Contributor

rvsia commented Apr 15, 2020

Scope: PF4 mapper

Description

Validating is set to true

Schema

const asyncValidator = () => new Promise((res) => setTimeout(() => res(), 1000));

export const wizardSchema = {
  fields: [
    {
      component: componentTypes.WIZARD,
      name: 'wizzard',
      crossroads: ['source.source-type'],
      //inModal: true,
      title: 'Title',
      showTitles: true,
      description: 'Description',
      buttonsPosition: 'left',
      fields: [
        {
          title: 'Get started with adding source',
          name: 1,
          nextStep: 'aws',
          fields: [
            {
              component: componentTypes.TEXTAREA,
              name: 'source.source-name',
              type: 'text',
              label: 'Source name',
              validate: [asyncValidator]
            }
          ]
        },
        {
          title: 'Configure AWS',
          name: 'aws',
          nextStep: 'summary',
          fields: [
            {
              component: componentTypes.TEXT_FIELD,
              name: 'aws-field',
              label: 'Aws field part',
              validate: [
                {
                  type: validatorTypes.REQUIRED
                }
              ],
              isRequired: true
            }
          ]
        },
        {
          fields: [
            {
              name: 'summary',
              component: 'summary'
            }
          ],
          name: 'summary',
          substepOf: 'Summary',
          title: 'Summary'
        }
      ]
    }
  ]
};

cc @Hyperkid123

@rvsia
Copy link
Contributor Author

rvsia commented Apr 15, 2020

error

@rvsia
Copy link
Contributor Author

rvsia commented Apr 15, 2020

The error occurred after updating React Final Form to 6.0.0

https://github.com/final-form/react-final-form/releases?after=v6.1.0

@rvsia
Copy link
Contributor Author

rvsia commented Apr 27, 2020

Current workaround until a fix in FF is released:

import { useEffect } from 'react';
import PropTypes from 'prop-types';
import useFormApi from '@data-driven-forms/react-form-renderer/dist/cjs/use-form-api';

const ValidatorReset = ({ name }) => {
    const formOptions = useFormApi();

    useEffect(() => {
        setTimeout(() => formOptions.change(name, '1'));

        return () => formOptions.change(name, '');
    }, []);

    return null;
};

ValidatorReset.propTypes = {
    name: PropTypes.string.isRequired
};

export default ValidatorReset;

This component will set a value to 1 after it is mounted, so the form is re-rendered. On unMount value is set to undefined. Be aware: when this component is on the last step, the value will stay in form values.

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

1 participant