Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
1d0742f to
934b86c
Compare
| ### `isItemValidAsync` | ||
|
|
||
| `isItemValidAsync` provides the same validation as `isItemValid`, but awaits any asynchronous `elements` sources that resolve to selectable options. Use this helper when your field definitions provide `Promise` or function-based `elements`. It returns a `Promise<boolean>` that resolves once all relevant element sources have been processed. | ||
|
|
||
| ### `useAsyncValidation` | ||
|
|
||
| `useAsyncValidation( item, fields, form )` is a React hook that performs the same asynchronous validation as `isItemValidAsync` and returns an object with `{ isValid, isResolving, validate }`. The `validate` function can be called to trigger validation manually, while `isResolving` indicates when validation is in progress. |
There was a problem hiding this comment.
I think we want to consolidate everything into a single API, not having three slightly different functions.
There was a problem hiding this comment.
If we want a single API and keep the current integration working, then the only way is probably to move the fetch to normalizeFields, but we'll end up with limited validation that only validates against fetched elements. It's not bad actually.
| } | ||
|
|
||
| try { | ||
| const elements = await resolveFieldElements( field.elements ); |
There was a problem hiding this comment.
This is fetching elements on mount. We discussed this here, where I suggested having a single place (normalizeFields?). But there's now 3 places where we have this logic: useFieldElements, resolveFieldElements, resolveFieldElements.
There was a problem hiding this comment.
Yes, both useFieldElements and resolveFieldsElements call resolveFieldElements in their body. But I agree that it's getting complex. The only concern with moving to normalizeFields for me is that we still have to make more requests for pagination and search, and we probably end up fetching in 2 places.
What?
Closes
Why?
How?
Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast