Skip to main content

Form Component

Form needs only two props to do its job, initialValues and onSubmit. There is, however, a number of props you can pass to make your life easier and in order to validate your form data.

Form Props#

NameTypeDefaultDescription
afterChangefunctionundefinedMiddleware that will be called with all the form data every time it changes afterChange(field, newFormData, errorCount, errors)
autoCompleteOffbooleanfalseDisable autocomplete
clearAfterSubmitbooleanfalseDoes what it says, clears the form back to initialValues after submit
disabledbooleanfalseProgramatically disable all inputs and buttons. In <FieldArray/> you will get back this property if you need it to ensure everything is disabled when you need it in case you don't have your condition in scope.
disableIffunctionundefinedA function to check if form data (or the updates using the diff algorithm you chose if any) is valid. If the function returns false, preventing will be aborted and the function passed on to onInvalidSubmit executed instead, if any. Ex: disableIf={updates => updates.foo.bar !== "baz"}
disableIfInvalidbooleanfalseSubmitting wont work until the form is valid according to your rules. If a function was passed to onInvalidSubmit, it will be executed instead.
disableIfNoUpdatesbooleanfalseSubmitting will have no effect until the form data has been changed in any way
initialValuesobjectundefinedThe initial form data the form will be populated with
onInvalidSubmitfunctionundefinedA callback that will be called upon invalid submit.
onResetfunctionundefinedAdditional tasks to perform with or without the values upon reset
onSubmitfunctionundefinedA callback that gets called with the form data
schemaValidationobject{}Accepts any functions you need to validate user input on a per-field basis
renderstring"div"This prop allows you to render a "form" tag instead of a "div" or any other native html tag. "div" is the default in order to support nested forms that control fields (you can't have a <form> inside of another <form> in browsers, this will generate bugs).
...restanyundefinedAny other props will be spread on to the <div> / <form> tag depending on what you chose to render.

Example Usage#

<FormautoCompleteOffclassName="I style the html form tag"clearAfterSubmitdisabled={someRequestStatus === "loading"}disableIf={data => data.options.breakfast.length > 15}disableIfInvaliddisableIfNoUpdatesinitialValues={{foo:"bar"}}onInvalidSubmit={() => alert("invalid form")}onReset={data => console.log("Reset!")}onSubmit={data => doSmthgWith(data)}schemaValidation={{foo: (str) => str.length > 0}}render="form"/>