React-final-form: Submitting a form with no event results in a runtime error (React Native)

Created on 27 Dec 2017  路  5Comments  路  Source: final-form/react-final-form

Are you submitting a bug report or a feature request?

Feature request

What is the current behavior?

Submitting a form with no event results in a runtime error.

What is the expected behavior?

I'm using React Final Form on React Native and I don't always have an event passed to the submit handler.

          <Form
                onSubmit={this.onSubmit}
                initialValues={/* ... */}
                render={({handleSubmit, reset, submitting, pristine, values}) => (
                    <View style={styles.container}>
                        <NavigationBar
                            leftButton="back"
                            onLeftButtonPress={this.props.navigator.pop}
                            rightButtonText={t("Save")}
                            onRightButtonPress={handleSubmit}
                        />
                ...
          </Form>

Sandbox Link

Obviously bad example just to show the error: https://codesandbox.io/s/k10xq99zmr

What's your environment?

React Native 0.48
Final Form 3.0.0
React Final Form 2.1.0

Other information

It's easy to bypass this error with this:

onRightButtonPress={() => {
    handleSubmit({preventDefault: () => {}});
}}

But I would rather have a check in the handleSubmit function to bypass the preventDefault call if no event is passed.

Most helpful comment

I'm happy to submit a PR

web image 2017-12-27 15-09-22

All 5 comments

I'm happy to submit a PR to https://github.com/final-form/react-final-form/blob/ec271773fd0f7b0c7f7fe0c4992bfcf021b63dc8/src/ReactFinalForm.js#L109

- event.preventDefault()
+ event && event.preventDefault()

I just need to check with Flow that everything still works

I'm happy to submit a PR

web image 2017-12-27 15-09-22

Shouldn't this issue be closed since #84 is merged?

Indeed. Thanks for your vigilance.

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

kiliw picture kiliw  路  4Comments

antoinerousseau picture antoinerousseau  路  3Comments

niros-welldone picture niros-welldone  路  3Comments

morloy picture morloy  路  4Comments

3dos picture 3dos  路  3Comments