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
Dan Harrin
Dan Harrin2y ago
no there is no way to drag elements between repeaters, i think that would be incredibly complex to implement
bernhard
bernhardOP2y ago
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:
bernhard
bernhardOP2y ago
josef
josef2y ago
instead of doing the database change, you can just change the form field array data, that should work better and immediately refresh the form
Dan Harrin
Dan Harrin2y ago
i dont think refreshFormData() is the right method here
bernhard
bernhardOP2y ago
Thanks for response! This are relationship fields, not regular arrays. What is the right method here?
Dan Harrin
Dan Harrin2y ago
@josef is right you should just be able to mutate the form data arrays
josef
josef2y ago
repeaters use arrays to represent and keep the state
Dan Harrin
Dan Harrin2y ago
so you can just change the data inside $this->data if you are in the livewire component already
bernhard
bernhardOP2y ago
Ah.. Thanks! That was it.
Want results from more Discord servers?
Add your server