Move elements between two nested repeaters
I have a
Repeater
form component, where the nested schema consists of a TextInput
(name) and another Repeater
(ok, its a Awcodes-Table-Repeater plugin, but that just extends the regular Repeater).
Is there a way, to add a button to the nested repeater elements to move the item from one parent "row" to another one?
I have already implemented a Placeholder with a button in it and a wire:click event, which I listen in the EditResource class, but form here I dont have an idea how to go on? Any hints or ideas?,10 Replies
no there is no way to drag elements between repeaters, i think that would be incredibly complex to implement
Well, I don't mean drag'n'drop.
What I have already achieved: I have already added a two buttons on each item, with
wire:click="moveIngredientGroupUp('.$groupId.', '.$rowId.')"
(and Down) on it. In my EditRecord class, I am listening on this two events and I have the methods for it, which do the database change for now. Then I am calling refreshFormData
with the name of the parent repeater. It works, but the repeater has empty fields and i have to reload. See video:instead of doing the database change, you can just change the form field array data, that should work better and immediately refresh the form
i dont think refreshFormData() is the right method here
Thanks for response! This are relationship fields, not regular arrays.
What is the right method here?
@josef is right
you should just be able to mutate the form data arrays
repeaters use arrays to represent and keep the state
so you can just change the data inside
$this->data
if you are in the livewire component alreadyAh.. Thanks! That was it.