Calling method in custom field type
I'm trying to create a new custom form field and I'm wondering if there's a way to call a method from the component class.
For example, if I have the following form field
and the class
I get the following error
Unable to call component method. Public method [doSomething] not found on component
The method obviously exists, but I think it's because the dynamic component doesn't really know where to look. Ss there a way to call the custom doSomething()
function in a dynamic component?Solution:Jump to solution
Form components aren't Livewire components, therefore your method cannot live in the custom field class.
You have two options:
1. Add the method to the page (ListRecords, ViewRecord, CreateRecord, EditRecord)...
4 Replies
+1
I can add that in my case, the component receiving the call is the Widget, not the Column. If I create a dummy doSomething() function in the widget definition class, the error disapears. Yet, it is useless!
Solution
Form components aren't Livewire components, therefore your method cannot live in the custom field class.
You have two options:
1. Add the method to the page (ListRecords, ViewRecord, CreateRecord, EditRecord)
2. Use events instead of methods. See how its done in https://github.com/search?q=repo%3Asaade%2Ffilament-adjacency-list%20builder%3A%3Asort&type=code
Linking to a code search like this is super clever! Will surely make use of that in the future π
Yeap, I also asked in the discussions forum and Events seems to be the best approach.
Here is the discussion link: https://github.com/filamentphp/filament/discussions/8865
GitHub
[v3][Forms] Call action function without rendering from custom fiel...
I'm trying to create a custom field and I want a way for the field to be able to change some internal state. For example let's say I have the following Component class OptionPicker extends ...