Multiple select for nested objects with IDs
Hi everyone. I'm trying to build a
Form.Item
with a Select inside for multiple related objects.
My base objects look like this:
So I want <Form.Item> to set an array of objects, not just numbers. It works just fine for “many-to-one” relation with NamePath (name={['relation', 'id']}
), but when it comes to “one-to-many” relation NamePath won't help.
I was trying to play with normalize
and other things, but with no luck.7 Replies
generous-apricot•2y ago
Hi @konstantinbodnia, Can you give more detailed information about what you want to do?
reporoduced code on github, stackblitz or codesandbox would be awesome 🙏
ambitious-aqua•2y ago
Hey @konstantinbodnia, I think i got what you're trying to achieve. 🤔
Let's start with using
name="relation"
instead of relation.id
And we can use getValueFromEvent
and getValueProps
to get/set the values to the form.
getValueFromEvent
callback can be used to get the value from the onChange
event of the Select
component. So you can map the value appropriately to your form state.
getValueProps
can be used to pass the values to the child element (in your case <Select>
)
I wonder which data provider you're using? If it's a compatible one with the @pankod/refine-inferencer
I think you should give it a try 🚀 Inferencer will try to resolve the data and create a code for your components. You can find a sample solution in its generated code and also it can give you a great head start 🚀ambitious-aqua•2y ago
Check out the docs of Ant design here: https://ant.design/components/form#formitem
national-gold•2y ago
I'm using
nestjsx/crud
as a data provider
these two functions did the trickambitious-aqua•2y ago
Great!
national-gold•2y ago
But for some reason it is now very slow...
Ok, thank you for your help, @aliemirs . This works.
But now I have one more following issue. The values won't get pre-selected in the edit form.
ambitious-aqua•2y ago
@konstantinbodnia can you check the
relationSelectProps
to see if its props are matching your getValueProps
? This might be the issue for the default values