a2c4a6a306
This fixes woocommerce/woocommerce-admin#5287 Major changes: 1. The `<Form>` component (which is a published component) gets a new optional prop (so its backward compatible), called `onChangeCallback`. This is called when any form value changes, allowing the controlling component to act on individual form changes. This was needed to utilise `<Form>` to revalidate and check if the user could access the next tab. This should not impact existing usages of the `<Form>`, but it could be good to test this. 2. Introduces a new flow for choosing business extensions that was specified in woocommerce/woocommerce-admin#5287 issue description. Please check the issue for reviewing the designs. The simplest way to implement this, ended up being keeping the existing flow intact and where necessary copy pasting code from those components into the new flow. This new flow is only shown if your segmentation matches the following: `Stores that selected the US as the country and Other or Food & Drinks as the industry |
||
---|---|---|
.. | ||
stories | ||
README.md | ||
index.js |
README.md
Form
A form component to handle form state and provide input helper props.
Usage
const initialValues = { firstName: '' };
<Form
onSubmitCallback={ ( 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 |
onSubmitCallback |
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 |
{} |