woocommerce/plugins/woocommerce-admin/packages/components/src/form
Joshua T Flowers dc175824c9 Hook up payments gateway data store (https://github.com/woocommerce/woocommerce-admin/pull/7038)
* Hook up payment gateway data store

* Fix deprecated onSubmitCallback in dynamic form

* Throw catchable errors in data store

* Provide a way to get errors from the data store

* Hook up payment connection update with data store

* Remove redundant requesting state on selectors

* Add changelog entry

* Handle PR feedback

* Fix linting errors
2021-05-26 14:31:30 -04:00
..
stories Update Form's documentation (https://github.com/woocommerce/woocommerce-admin/pull/6708) 2021-05-18 14:24:24 +10:00
README.md Hook up payments gateway data store (https://github.com/woocommerce/woocommerce-admin/pull/7038) 2021-05-26 14:31:30 -04:00
index.js Update Form's documentation (https://github.com/woocommerce/woocommerce-admin/pull/6708) 2021-05-18 14:24:24 +10:00

README.md

Form

A form component to handle form state and provide input helper props.

Usage

const initialValues = { firstName: '' };

<Form
	onSubmit={ ( values ) => {} }
	initialValues={ initialValues }
>
	{ ( {
		getInputProps,
		values,
		errors,
		handleSubmit,
	} ) => (
		<div>
			<TextControl
				label={ 'First Name' }
				{ ...getInputProps( 'firstName' ) }
			/>
			<Button
				isPrimary
				onClick={ handleSubmit }
				disabled={ Object.keys( errors ).length }
			>
				Submit
			</Button>
		</div>
	) }
</Form>

Props

Name Type Default Description
children * null A renderable component in which to pass this component's state and helpers. Generally a number of input or other form elements
errors Object {} Object of all initial errors to store in state
initialValues Object {} Object key:value pair list of all initial field values
onSubmit Function noop Function to call when a form is submitted with valid fields
validate Function noop A function that is passed a list of all values and should return an errors object with error response
touched Object {} This prop helps determine whether or not a field has received focus
onChange Function null A function that receives the value of the input; called when selected items change, whether added, edited, or removed