How to update form field from resource Edit page's method?
I have resource edit form. In one placeholder field I am including my custom Livewire component. My Livewire component dispatches event 'update-stock' and with event it is sending $productId and $stock info. I am listening for that event on my resource edit page and when method is triggered I want to update stock field in the underlying form. But for some reason that stock variable doesn't change.
This is code from my resource edit page:
As you can see I was trying to manipulate field values directly in $data array, but that doesn't work. When form is rendered I still see old stock value in the form.
Solution:Jump to solution
After some more debugging problem was the way I was updating the value. This is foreach loop that made everything working fine:
```
$items = $this->data['taskItems'];
...
2 Replies
Update: If I dump all the form data in
updateProductStock()
method I can see that I've changed the quantity, but in the form it is still the old value.
After foreach loop in my updateProductStock()
method I've added:
When my livewire component dispatches 'update-stock' event, my method updateProductStock()
is executed and modal pops up with dumped data. I can see that I've changed stock value, but it is not reflected in the form.Solution
After some more debugging problem was the way I was updating the value. This is foreach loop that made everything working fine:
I think that has nothing to do with filament but rather how PHP works.