F
Filament4w ago
lmtc

KeyValue not saving new order

Hopefully someone has an idea where I'm going wrong - I have this inside a repeater:
KeyValue::make('options.select_options')
->label('Select Options')
->columnSpan('full')
->reorderable()
->keyLabel('Stored Value')
->valueLabel('Display Value')
->addActionLabel('Add option')
->visible(fn($get) => $get('type') === 'select_field'),
KeyValue::make('options.select_options')
->label('Select Options')
->columnSpan('full')
->reorderable()
->keyLabel('Stored Value')
->valueLabel('Display Value')
->addActionLabel('Add option')
->visible(fn($get) => $get('type') === 'select_field'),
but when I save it reverts to the old order?
8 Replies
toeknee
toeknee4w ago
Do the options relation have the order column? does the DB ever get updated? I would tend to use telescope and monitor the request
lmtc
lmtcOP4w ago
It's not a relation, it's the same table just another field. I'll have a look at the request!
toeknee
toeknee4w ago
I'm a little confused how options.select_options work usually this would mean options is a relationship...
lmtc
lmtcOP4w ago
Yea I probably should have done that - this is in a modal and I have a field called options I'm submitting to - this is my full code for this repeater:
toeknee
toeknee4w ago
I am guessing it's to do with your action method, try DDing and seeing if you get it correctly
lmtc
lmtcOP5d ago
@toeknee sorry! Just getting back to this - I did get the dd of $state to output the correct values and working correctly, but when I save it will save in alphabetical order?
Dan Harrin
Dan Harrin5d ago
The order could be reset by PHP, JS or your database, object order is never really guaranteed, only array items with numeric keys
lmtc
lmtcOP5d ago
Yea that's what I'm thinking - I have it cast as an array as well and state comes through correctly so it could be the db yea... it's the db 😦 all good thanks for pointing me in the right direction! easy fix at least! Just in case someone has the same issue - I realised I had a typo and the type of the field in the db was set to jsonb instead of json

Did you find this page helpful?