feat: expose index in FormDataConsumer - #11343
Conversation
| if (arraySource) { | ||
| const scopedFormData = get(formData, arraySource); | ||
| result = children({ formData, scopedFormData }); | ||
| const index = Number(arraySource.match(/\d+$/)?.[0]); |
There was a problem hiding this comment.
This won't work for nested arrays (e.g. some.1.foo.2.bar). You should instead take the last match I believe.
There was a problem hiding this comment.
Updated to use matchAll and take the last match to handle nested arrays correctly. Also added a test for nested ArrayInput.
fzaninotto
left a comment
There was a problem hiding this comment.
Nice! But could you also update the doc to make this new feature discoverable? E.g. in https://marmelab.com/react-admin/Inputs.html#linking-two-inputs
Thanks for the feedback! I've updated the documentation to make the new index parameter discoverable. |
Fixes #10498
Problem
FormDataConsumerexposesformDataandscopedFormData, but does not expose the index of the current item when used inside anArrayInput.Solution
Expose the current
ArrayInputitem index throughFormDataConsumerRenderParams.The index is extracted from the array source and passed to the render function.
How To Test
FormDataConsumerinside anArrayInput.Additional Checks
nextfor a feature