F
Filament5mo ago
Anish

Array Order

I have an array of this kind

[
'Option 1',
'Option 2',
'Option 3',
]

[
'Option 1',
'Option 2',
'Option 3',
]
I need a form element in which the user may re-order this array to achieve something like

[
'Option 2',
'Option 1',
'Option 3',
]

[
'Option 2',
'Option 1',
'Option 3',
]
but can't delete / add / update any option. I am trying with Repeater, but the results are not very good.
Thanks in advance for any suggestions / pointers.
3 Replies
Dennis Koch
Dennis Koch5mo ago
I am trying with Repeater, but the results are not very good.
Why, what's the issue? Try ->simple() repeater.
Anish
Anish5mo ago
Is there some documentation? Can you provide some code example? Thanks. I have this situation : Student model with default values
$student->options = [ "Kolkata", "Delhi", "Bengaluru", "Chennai"];
$student->options = [ "Kolkata", "Delhi", "Bengaluru", "Chennai"];
I am not sure how is Repeater will work :
Repeater::make('options')
->label('Location Preferences')
->simple(
TextInput::make('preference')
->required(),
)
->deletable(false)
->addable(false)
Repeater::make('options')
->label('Location Preferences')
->simple(
TextInput::make('preference')
->required(),
)
->deletable(false)
->addable(false)
But this is not showing anything. Fixed it, I was trying to get the values from the $data. I should have run it through getState(). Many thanks.
Dennis Koch
Dennis Koch5mo ago
Not really needed. That code should work if options is casted as an array