mirror of
https://github.com/elyby/accounts-frontend.git
synced 2025-01-16 00:23:10 +05:30
#305: fix form loading state in case, when submit handler does not returns a promise
This commit is contained in:
parent
44b9f2ba55
commit
560d3e660c
@ -110,15 +110,17 @@ export default class Form extends Component<Props, State> {
|
||||
}
|
||||
|
||||
if (form.checkValidity()) {
|
||||
const result = this.props.onSubmit(
|
||||
this.props.form ? this.props.form : new FormData(form)
|
||||
);
|
||||
|
||||
if (result && result.then) {
|
||||
this.setState({isLoading: true});
|
||||
|
||||
Promise.resolve(this.props.onSubmit(
|
||||
this.props.form ? this.props.form : new FormData(form)
|
||||
))
|
||||
.catch((errors: {[key: string]: string}) => {
|
||||
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 = {};
|
||||
|
Loading…
x
Reference in New Issue
Block a user