Redux-form: Passing options to onSubmit?

Created on 27 Mar 2016  路  2Comments  路  Source: redux-form/redux-form

Hi

I have a form where the user can either 'Send' or 'Send & Archive' a conversation.

I was to bind an 'archive' flag to the onSubmit callback when the user clicks the Send & Archive, but the parameters are overwritten by the formvalues provided by ReduxForm

How can this be accomplished?

question

Most helpful comment

How's this?

const makeSender = archive =>
  (values, dispatch) => {
    dispatch(send({
      ...values,
      archive
    }))
  }
}

<button onClick={handleSubmit(makeSender(false))}>Send</button>
<button onClick={handleSubmit(makeSender(true))}>Send & Archive</button>

All 2 comments

How's this?

const makeSender = archive =>
  (values, dispatch) => {
    dispatch(send({
      ...values,
      archive
    }))
  }
}

<button onClick={handleSubmit(makeSender(false))}>Send</button>
<button onClick={handleSubmit(makeSender(true))}>Send & Archive</button>

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chienvuhoang picture chienvuhoang  路  3Comments

tylergoodman picture tylergoodman  路  3Comments

srajchevski picture srajchevski  路  3Comments

wtfil picture wtfil  路  3Comments

tejans24 picture tejans24  路  3Comments