public function removeCoreFunction($index){
unset($this->coreFunctions[$index]);
$this->coreFunctions = array_values($this->coreFunctions);
}
so i have this function here which removes the specific index from the coreFunctions and makes it an array value again. It works as i expected in the function, however in my blade file, it does not update the real data for that index.
<textarea type="text" rows="10" id="coreFunctions_{{$index}}_accomp"
name="coreFunctions[{{$index}}][accomp]"
wire:model.blur="coreFunctions.{{$index}}.accomp"
class="block p-2.5 w-full text-sm text-gray-900 bg-gray-50 rounded-lg border border-gray-300 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500">
I alr tried the .live and etc.
2
Answers
I added this to my public function removeCoreFunction:
and i added this to my blade file
The context is not entirely clear, since we can’t see the relevant parts of the class and the view, so I will try to deduce some elements.
If the assumed scenario does not reflect your situation, please post the relevant parts of the class and view.
Since there is an $Index I assume that there is a loop that displays some elements of an array.
I assume also there is a delete button (or equivalent) that calls removeCoreFunction() to delete a row from the array.
The "rows" displayed by the loop must be contained in a tag with an unique wire:key (unique in an absolute sense, in the DOM and also in the dataset) to let understand Livewire which row to update in the DOM.
The array index, since is compacted by array_values() is not a good candidate (the indexes are reassigned)
You have a couple of options for wire:key:
This is a hypothetical part of the view using $index as wire:key :
The related removeCoreFunction() becomes:
If instead you have a unique id column available:
The related removeCoreFunction() can be the same as above which uses unset() or, if you want to keep indexes contiguous, it can be simplified like this: