submit()

Specification

Performs a manual submit of the current Form. Submit function returns a Promise that resolves into different SubmitState.
Manual submit is meant for explicit usage scenarios, and is not a conventional way of submitting your forms. If you are not sure if you need manual submit, then you don't need it.

Definition

1
type Submit = () => Promise<SubmitState>
Copied!

Example

1
import React from 'react'
2
import { Form } from 'react-advanced-form'
3
import { Input } from 'react-advanced-form-addons'
4
5
export default class Example extends React.Component {
6
handleSubmit = () => {
7
// Make sure to return a Promise here
8
}
9
10
handleClick = () => {
11
this.form.submit().then((submitState) => {
12
// This is called after the Promise of `this.handleSubmit` resolves/rejects
13
})
14
}
15
16
render() {
17
return (
18
<div>
19
<Form
20
ref={form => this.form = form}
21
action={this.handleSubmit}>
22
<Input
23
name="username"
24
required />
25
</Form>
26
27
<a href="#" onClick={this.handleClick}>Submit manually</a>
28
</div>
29
)
30
}
31
}
Copied!
Make sure to provide Form.props.action since that will be invoked after calling manual submit of the form.
Last modified 3yr ago