Form field value based on 2 other fields
Docs show how to generate the value of a slug field. And shoes how to test against the old value of the field before changing it.
How to fill the value of a field based on the values of 2 other fields?
And only fill the third field if it is empty: don't change it if it already has value.
4 Replies
Can you provide a real example with the "other fields" to help you precicely?
You can just use a combination of
Get
, Set
, and afterStateUpdated
:
this is an example from the docs:
https://filamentphp.com/docs/3.x/forms/advanced#generating-a-slug-from-a-titleHere is the code I tried on the basis of the 'generating-a-slug-from-a-title' example in docs.
The idea is that the field src_code will be generated by a helper function based on two other fields: leader, a string and execdir_id, an int.
I don't know what is happening, but the first one works (leader) but nothing seems to happen when I change the execdir_id field (it is a select drop down).
It eventually gives a max execution time exceeded error in the background.
Solution
Solved:
My problem was in the Helper function. It wasn't returning.