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()) {
|
if (form.checkValidity()) {
|
||||||
this.setState({isLoading: true});
|
const result = this.props.onSubmit(
|
||||||
|
|
||||||
Promise.resolve(this.props.onSubmit(
|
|
||||||
this.props.form ? this.props.form : new FormData(form)
|
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);
|
this.setErrors(errors);
|
||||||
})
|
}).finally(() => this.setState({isLoading: false}));
|
||||||
.finally(() => this.setState({isLoading: false}));
|
}
|
||||||
} else {
|
} else {
|
||||||
const invalidEls = form.querySelectorAll(':invalid');
|
const invalidEls = form.querySelectorAll(':invalid');
|
||||||
const errors = {};
|
const errors = {};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user