#305: fix form loading state in case, when submit handler does not returns a promise

This commit is contained in:
SleepWalker 2017-10-28 17:03:38 +03:00
parent 44b9f2ba55
commit 560d3e660c

View File

@ -110,15 +110,17 @@ export default class Form extends Component<Props, State> {
}
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 = {};