From 560d3e660cbc99bc5d097f1180fcb6ac75efd06a Mon Sep 17 00:00:00 2001 From: SleepWalker Date: Sat, 28 Oct 2017 17:03:38 +0300 Subject: [PATCH] #305: fix form loading state in case, when submit handler does not returns a promise --- src/components/ui/form/Form.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/components/ui/form/Form.js b/src/components/ui/form/Form.js index b928853..6a97feb 100644 --- a/src/components/ui/form/Form.js +++ b/src/components/ui/form/Form.js @@ -110,15 +110,17 @@ export default class Form extends Component { } if (form.checkValidity()) { - this.setState({isLoading: true}); - - Promise.resolve(this.props.onSubmit( + const result = this.props.onSubmit( this.props.form ? this.props.form : new FormData(form) - )) - .catch((errors: {[key: string]: string}) => { + ); + + if (result && result.then) { + this.setState({isLoading: true}); + + result.catch((errors: {[key: string]: string}) => { this.setErrors(errors); - }) - .finally(() => this.setState({isLoading: false})); + }).finally(() => this.setState({isLoading: false})); + } } else { const invalidEls = form.querySelectorAll(':invalid'); const errors = {};