Search code examples
reactjsreduxredux-form

What to do if your submit is outside of redux-form


What to do if your submit is outside of form?

Example:

<Root>
  <Header>
    <Button label={'SAVE'} onClick={this.clickHandler}/>  // <-- My handler for save form data
    <Button label={'DELETE'} />
  </Header>

  <Form onSubmit={this.handleSubmit} fields={fieldsList} /> // <-- My form
<Root />

Should I be using getValues?


Solution

  • From v4.2.0 you can add a ref prop to your form component and call submit() on that ref. See example at http://redux-form.com/5.3.1/#/examples/submit-from-parent

    clickHandler() {
      this.refs.myForm.submit()
    }
    
    <Root>
      <Header>
        <Button label={'SAVE'} onClick={this.clickHandler}/>
        <Button label={'DELETE'} />
      </Header>
      <Form ref="myForm" fields={fieldsList} />
    </Root>