Redux-form: display a list of errors on top of a page

前端 未结 2 1113
余生分开走
余生分开走 2021-02-07 04:48

I want to use Redux-form in a manner that changes input color & displays the actual error on top of the page. How do I access the list of current field errors outside the fi

2条回答
  •  野性不改
    2021-02-07 05:48

    You can use the state selectors provided by redux-form.

    In particular, getFormSubmitErrors will give you the submit validation errors:

    import { getFormSubmitErrors } from 'redux-form';
    
    // ...
    
    const MyFormWithErrors = connect(state => ({
      submitErrors: getFormSubmitErrors('my-form')(state)
    }))(MyForm);
    

    The original, unconnected MyForm component might look like this:

    const MyForm = reduxForm({
      form: 'my-form',
    })(ManageUserProfile);
    

    If you want to display the synchronous validation errors, you can use the getFormSyncErrors selector instead.

提交回复
热议问题