Hey guys, I have problem when I want to swap field component of relationship, and use
useField
hook to update the field. To add the items it works, but somehow I can't change the order of items.
I use setValue with an array, i.e.
initialValue ->
['a', 'b', 'c']
then
setValue(['c', 'b', 'a'])
then refresh page still
['a', 'b', 'c']
it is works when i add item, i.e
['a', 'b', 'c', 'd']
Is there another way to set item's order?
hi @rrums - where are you getting the array of data from? as you can sort on requests
https://payloadcms.com/docs/queries/overview#sortnot to querying, but to store data (array of IDs)
because i swapped the field component, but i can't change order of the IDs
like this -> i log the
value
, it has correct arrays, the order is set as I drag the item. But it wasn't stored with correct order.
FYI, the field on collection
{
name: 'items',
type: 'relationship',
relationTo: 'menuItems',
hasMany: true,
required: true,
admin: {
components: {
Field: MenuSelect // custom component
},
isSortable: true,
}
}
Curious, what does the network panel look like for this request?
ouch found the problem, because I fetch not from initialValue. My bad.
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.