From 9b1fd7d6e9acc79a34fddd6901ce8a8bd39d5d21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Mon, 4 Mar 2019 17:14:21 +0100 Subject: [PATCH] Lock handleSubmit while submitting --- src/ReactFinalForm.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/ReactFinalForm.js b/src/ReactFinalForm.js index 6af2a01a..36020214 100644 --- a/src/ReactFinalForm.js +++ b/src/ReactFinalForm.js @@ -44,6 +44,7 @@ class ReactFinalForm extends React.Component { state: State form: FormApi mounted: boolean + submitLock: boolean resumeValidation: ?boolean unsubscriptions: Unsubscribe[] @@ -59,6 +60,7 @@ class ReactFinalForm extends React.Component { } = props const config: Config = rest this.mounted = false + this.submitLock = false try { this.form = createForm(config) } catch (e) { @@ -101,7 +103,23 @@ class ReactFinalForm extends React.Component { event.stopPropagation() } } - return this.form.submit() + + if (this.submitLock) { + return + } + + const onComplete = () => (this.submitLock = false) + + this.submitLock = true + const result = this.form.submit() + + if (result && typeof result.then === 'function') { + result.then(onComplete, onComplete) + } else { + onComplete() + } + + return result } componentWillMount() {