Autofill TextInput based on Select value in FilamentPhp
I am developing a project in FilamentPhp and I have encountered the following problem that I do not know how to solve.
I would like to be able to auto-complete a TextInput dynamically depending on the value I select in a Select, that is, the logic would be the following:
I select an option from the Select
I make a query with the selected option from the Select to retrieve all the information from the model
I auto-fill the TextInput with the retrieved information.
Can anyone help me with this?
Regards
Solution:Jump to solution
This is possible, check the following over the docs:
- Form reactivity - live() method: https://filamentphp.com/docs/3.x/forms/advanced#the-basics-of-reactivity
- Set the state of another field: https://filamentphp.com/docs/3.x/forms/advanced#injecting-a-function-to-set-the-state-of-another-field...
2 Replies
Solution
This is possible, check the following over the docs:
- Form reactivity - live() method: https://filamentphp.com/docs/3.x/forms/advanced#the-basics-of-reactivity
- Set the state of another field: https://filamentphp.com/docs/3.x/forms/advanced#injecting-a-function-to-set-the-state-of-another-field
- Getting the state of another field:
https://filamentphp.com/docs/3.x/forms/advanced#injecting-a-function-to-set-the-state-of-another-field
So, this would work like:
So when you update the select "this_will_trigger" it will find that id on YourModel and update the textinput "this_field_will_update"
Thank you very much for the explanation. Regards