React Advanced Form
  • Introduction
  • General
    • Comparison
      • Compared to Formik
      • Compared to Final form
    • Migration guides
      • 1.4.x → 1.5.x
    • FAQ
  • Getting started
    • Installation
    • Creating fields
    • Creating form
    • Validation rules
    • Validation messages
    • Applying validation
    • Handle submit
  • Architecture
    • Argument properties
    • Referencing
    • Field lifecycle
    • Controlled fields
    • Reactive props
  • Validation
    • Getting started
    • Validation schema
      • Rule definition
      • Reactive rule
    • Validation messages
  • High-order components
    • createField
      • Options
      • Field presets
      • Exposed props
  • Components
    • FormProvider
    • Form
      • Props
        • innerRef
        • initialValues
        • action
        • rules
        • messages
      • Methods
        • setValues()
        • setErrors()
        • reset()
        • validate()
        • serialize()
        • submit()
      • Callbacks
        • onFirstChange
        • onReset
        • onInvalid
        • onSerialize
        • onSubmitStart
        • onSubmitted
        • onSubmitFailed
        • onSubmitEnd
    • Field.Group
    • Field
      • Props
        • rule
        • asyncRule
        • skip
      • Callbacks
        • onFocus
        • onChange
        • onBlur
  • Recipes
    • Generating a form
    • Utilizing functions
  • Developers
    • Contributing
Powered by GitBook
On this page
  • Specification
  • Definition
  • Example
  1. Components
  2. Form
  3. Methods

submit()

Previousserialize()NextCallbacks

Last updated 6 years ago

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 of submitting your forms. If you are not sure if you need manual submit, then you don't need it.

Definition

type Submit = () => Promise<SubmitState>

Example

import React from 'react'
import { Form } from 'react-advanced-form'
import { Input } from 'react-advanced-form-addons'

export default class Example extends React.Component {
 handleSubmit = () => {
   // Make sure to return a Promise here
  }

  handleClick = () => {
    this.form.submit().then((submitState) => {
      // This is called after the Promise of `this.handleSubmit` resolves/rejects
    })
  }

  render() {
    return (
      <div>
        <Form
          ref={form => this.form = form}
          action={this.handleSubmit}>
          <Input
            name="username"
            required />
        </Form>

        <a href="#" onClick={this.handleClick}>Submit manually</a>
      </div>
    )
  }
}

Make sure to provide Form.props.action since that will be invoked after calling manual submit of the form.

conventional way