-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add docs for form validation #5343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1f81379
Initial pass at forms guide and textfield validation docs
devongovett b1cdcb2
Add validation section to all RAC docs
devongovett 9379759
Add Form component page
devongovett 91ceb7a
Spectrum validation docs
devongovett 0e4e761
Pass native error message from datepicker to calendar
devongovett 009f2cf
Workaround textarea bug
devongovett 505c527
fix ts
devongovett 75cb1c3
Recommend useSubmit instead of FormValidationContext for remix
devongovett 016649c
Fix heading
devongovett bf3be8a
Merge branch 'main' of github.com:adobe/react-spectrum into validatio…
devongovett 7c12240
Merge branch 'main' into validation-docs
devongovett File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -266,41 +266,34 @@ function AsyncLoadingExample() { | |
| ``` | ||
|
|
||
| ## Validation | ||
| SearchAutocomplete can display a validation state to communicate to the user whether the current value is valid or invalid. | ||
| Implement your own validation logic in your app and pass either `"valid"` or `"invalid"` to the SearchAutocomplete via the `validationState` prop. | ||
|
|
||
| The example below illustrates how one would validate if the user has entered a valid email into the SearchAutocomplete. | ||
| ```tsx example | ||
| function Example() { | ||
| let [value, setValue] = React.useState('[email protected]'); | ||
| let isValid = React.useMemo(() => /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(value), [value]); | ||
| SearchAutocomplete supports the `isRequired` prop to ensure the user enters a value, as well as custom client and server-side validation. It can also be integrated with other form libraries. See the [Forms](forms.html) guide to learn more. | ||
|
|
||
| let options = [ | ||
| {id: 1, email: '[email protected]'}, | ||
| {id: 2, email: '[email protected]'}, | ||
| {id: 3, email: '[email protected]'}, | ||
| {id: 4, email: '[email protected]'}, | ||
| {id: 5, email: '[email protected]'}, | ||
| {id: 6, email: '[email protected]'}, | ||
| {id: 7, email: '[email protected]'}, | ||
| {id: 8, email: '[email protected]'}, | ||
| {id: 9, email: '[email protected]'} | ||
| ]; | ||
| When the [Form](Form.html) component has the `validationBehavior="native"` prop, validation errors block form submission and are displayed as help text automatically. Errors are displayed when the user blurs the search field or submits the form. | ||
|
|
||
| return ( | ||
| <SearchAutocomplete | ||
| width="size-3000" | ||
| label="Search Email Addresses" | ||
| validationState={isValid ? 'valid' : 'invalid'} | ||
| defaultItems={options} | ||
| inputValue={value} | ||
| onInputChange={setValue}> | ||
| {item => <Item>{item.email}</Item>} | ||
| </SearchAutocomplete> | ||
| ); | ||
| } | ||
| ```tsx example | ||
| import {Form, ButtonGroup, Button} from '@adobe/react-spectrum'; | ||
|
|
||
| <Form validationBehavior="native" maxWidth="size-3000"> | ||
| {/*- begin highlight -*/} | ||
| <SearchAutocomplete label="Favorite animal" name="animal" isRequired> | ||
| {/*- end highlight -*/} | ||
| <Item>Aardvark</Item> | ||
| <Item>Cat</Item> | ||
| <Item>Dog</Item> | ||
| <Item>Kangaroo</Item> | ||
| <Item>Panda</Item> | ||
| <Item>Snake</Item> | ||
| </SearchAutocomplete> | ||
| <ButtonGroup> | ||
| <Button type="submit" variant="primary">Submit</Button> | ||
| <Button type="reset" variant="secondary">Reset</Button> | ||
| </ButtonGroup> | ||
| </Form> | ||
| ``` | ||
|
|
||
| By default, `SearchAutocomplete` displays default validation messages provided by the browser. See [Customizing error messages](forms.html#customizing-error-messages) in the Forms guide to learn how to provide your own custom errors. | ||
|
|
||
| ## Custom Filtering | ||
| By default, SearchAutocomplete uses a string "contains" filtering strategy when deciding what items to display in the dropdown menu. This filtering strategy can be overwritten | ||
| by filtering the list of items yourself and passing the filtered list to the SearchAutocomplete via the `items` prop. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -658,42 +658,34 @@ function AsyncLoadingExample() { | |
| ``` | ||
|
|
||
| ## Validation | ||
| ComboBox can display a validation state to communicate to the user whether the current value is valid or invalid. | ||
| Implement your own validation logic in your app and pass either `"valid"` or `"invalid"` to the ComboBox via the `validationState` prop. | ||
|
|
||
| The example below illustrates how one would validate if the user has entered a valid email into the ComboBox. | ||
| ```tsx example | ||
| function Example() { | ||
| let [value, setValue] = React.useState('[email protected]'); | ||
| let isValid = React.useMemo(() => /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(value), [value]); | ||
| ComboBox supports the `isRequired` prop to ensure the user enters a value, as well as custom client and server-side validation. It can also be integrated with other form libraries. See the [Forms](forms.html) guide to learn more. | ||
|
|
||
| let options = [ | ||
| {id: 1, email: '[email protected]'}, | ||
| {id: 2, email: '[email protected]'}, | ||
| {id: 3, email: '[email protected]'}, | ||
| {id: 4, email: '[email protected]'}, | ||
| {id: 5, email: '[email protected]'}, | ||
| {id: 6, email: '[email protected]'}, | ||
| {id: 7, email: '[email protected]'}, | ||
| {id: 8, email: '[email protected]'}, | ||
| {id: 9, email: '[email protected]'} | ||
| ]; | ||
| When the [Form](Form.html) component has the `validationBehavior="native"` prop, validation errors block form submission and are displayed as help text automatically. Errors are displayed when the user blurs the combo box or submits the form. | ||
|
|
||
| return ( | ||
| <ComboBox | ||
| width="size-3000" | ||
| label="To:" | ||
| validationState={isValid ? 'valid' : 'invalid'} | ||
| defaultItems={options} | ||
| inputValue={value} | ||
| onInputChange={setValue} | ||
| allowsCustomValue> | ||
| {item => <Item>{item.email}</Item>} | ||
| </ComboBox> | ||
| ); | ||
| } | ||
| ```tsx example | ||
| import {Form, ButtonGroup, Button} from '@adobe/react-spectrum'; | ||
|
|
||
| <Form validationBehavior="native" maxWidth="size-3000"> | ||
| {/*- begin highlight -*/} | ||
| <ComboBox label="Favorite animal" name="animal" isRequired> | ||
| {/*- end highlight -*/} | ||
| <Item>Aardvark</Item> | ||
| <Item>Cat</Item> | ||
| <Item>Dog</Item> | ||
| <Item>Kangaroo</Item> | ||
| <Item>Panda</Item> | ||
| <Item>Snake</Item> | ||
| </ComboBox> | ||
| <ButtonGroup> | ||
| <Button type="submit" variant="primary">Submit</Button> | ||
| <Button type="reset" variant="secondary">Reset</Button> | ||
| </ButtonGroup> | ||
| </Form> | ||
| ``` | ||
|
|
||
| By default, `ComboBox` displays default validation messages provided by the browser. See [Customizing error messages](forms.html#customizing-error-messages) in the Forms guide to learn how to provide your own custom errors. | ||
|
|
||
| ## Custom Filtering | ||
| By default, ComboBox uses a string "contains" filtering strategy when deciding what items to display in the dropdown menu. This filtering strategy can be overwritten | ||
| by filtering the list of items yourself and passing the filtered list to the ComboBox via the `items` prop. | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.