Repeater - Safe Approach to Prepend Data

I can't seem to find a path with the Repeater component to safely add a new item to the start of the list. I have the two following approaches:
// Use internal Filament events to add the new item and move it to the start of the list
public function addFormItem() {
$this->mountFormComponentAction('data.criteria', 'add');
$ids = array_keys($this->data['criteria']);
$newItemId = array_pop($ids);
$ids = [$newItemId, ...$ids];
$this->mountFormComponentAction('data.criteria', 'reorder', [
'items' => $ids
]);
}
// Use internal Filament events to add the new item and move it to the start of the list
public function addFormItem() {
$this->mountFormComponentAction('data.criteria', 'add');
$ids = array_keys($this->data['criteria']);
$newItemId = array_pop($ids);
$ids = [$newItemId, ...$ids];
$this->mountFormComponentAction('data.criteria', 'reorder', [
'items' => $ids
]);
}
// Manually add to the state
public function addFormItem()
{
$newItem = [str()->ulid()->toRfc4122() => ['new-repeater' => 'contents-here']];

$this->data['criteria'] = $newItem + $this->data['criteria'];
}
// Manually add to the state
public function addFormItem()
{
$newItem = [str()->ulid()->toRfc4122() => ['new-repeater' => 'contents-here']];

$this->data['criteria'] = $newItem + $this->data['criteria'];
}
The new item shows up, but they seem to break repeater collapsing functionality. Is there a better way to handle this?
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server