-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Form lib] Allow dynamic data to be passed to validator functions (#1…
- Loading branch information
Showing
13 changed files
with
650 additions
and
28 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
src/plugins/es_ui_shared/static/forms/docs/core/use_async_validation_data.mdx
This file contains 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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
id: formLibCoreUseAsyncValidationData | ||
slug: /form-lib/core/use-async-validation-data | ||
title: useAsyncValidationData() | ||
summary: Provide dynamic data to your validators... asynchronously | ||
tags: ['forms', 'kibana', 'dev'] | ||
date: 2021-08-20 | ||
--- | ||
|
||
**Returns:** `[Observable<T>, (nextValue: T|undefined) => void]` | ||
|
||
This hook creates for you an observable and a handler to update its value. You can then pass the observable directly to <DocLink id="formLibCoreUseField" section="validationData$" text="the field `validationData$` prop" />. | ||
|
||
See an example on how to use this hook in the <DocLink id="formLibExampleValidation" section="asynchronous-dynamic-data-in-the-validator" text="asynchronous dynamic data in the validator" /> section. | ||
|
||
## Options | ||
|
||
### state (optional) | ||
|
||
**Type:** `any` | ||
|
||
If you provide a state when calling the hook, the observable value will keep in sync with the state. | ||
|
||
```js | ||
const MyForm = () => { | ||
... | ||
const [indices, setIndices] = useState([]); | ||
// Whenever the "indices" state changes, the "indices$" Observable will be updated | ||
const [indices$] = useAsyncValidationData(indices); | ||
|
||
... | ||
|
||
<UseField path="indexName" validationData$={indices$} /> | ||
|
||
} | ||
``` |
This file contains 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 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
Oops, something went wrong.