Unable to call component method. Public method [setValue] not found on component

blade file
<button wire:click.prevent="setValue({{ $i }})">
<button wire:click.prevent="setValue({{ $i }})">
component
protected string $view = 'forms.components.star-rating';

protected int $value = 2;
protected int $maxStars = 5;

public function setValue(int $value): void
{
$this->value = $value;
}
protected string $view = 'forms.components.star-rating';

protected int $value = 2;
protected int $maxStars = 5;

public function setValue(int $value): void
{
$this->value = $value;
}
14 Replies
bwurtz999
bwurtz99915mo ago
did you set protected $listeners = ['setValue'];?
GeRaged | Niklas
GeRaged | NiklasOP15mo ago
Unable to call component method. Public method [$emit] not found on component Unable to call component method. Public method [emit] not found on component
awcodes
awcodes15mo ago
Is your component actually a livewire component? Otherwise it won’t work the way you are trying to do it.
GeRaged | Niklas
GeRaged | NiklasOP15mo ago
I am trying to build my own component but it is not described anywhere. Neither in the documentation nor in any Yt video
awcodes
awcodes15mo ago
important thing to remember is that form components aren't Livewire components. you can certainly make your custom form component a Livewire component.
GeRaged | Niklas
GeRaged | NiklasOP15mo ago
And how can I make my Field Component be a livewire component?
awcodes
awcodes15mo ago
the same way you'd make any livewire component, then you'd just put it in the blade view for your custom field. I will say though, that there is a reason that fields aren't individual livewire components.
GeRaged | Niklas
GeRaged | NiklasOP15mo ago
I am currently try to build a filterable checkbox list where I can filter by the checkbox group But I am struggeling to bind the select where I can select the groups and the saving it to a variable in the component an then filter the checkboxes by the group of the select Can you give me an example how I can render a livewire component inside a Field Component?
awcodes
awcodes15mo ago
Sorry, i don't have time to put anything together for you. Maybe someone else does, but it's all standard laravel and livewire.
Vincent
Vincent15mo ago
Sorry to bump an old thread -- I actually just ran into this. The docs for Custom Fields seem to imply that individual fields are Livewire components, but doesn't explicitly say "this is not a livewire component, just a Blade component". For instance, it says:
This is the basis of how fields work in Filament. Each field is assigned to a public property in the Livewire component class, which is where the state of the field is stored. We call the name of this property the "state path" of the field.
I'm guessing the "Livewire component class" here is whatever context the Custom Field appears in (e.g. a Page, Widget, etc.)? (I could also be super confused here, trying to build a dynamic custom field)
awcodes
awcodes15mo ago
Yes. For example in the panels, the pages are the livewire components. The form / table goes in the livewire component and the fields go inside the form.
Vincent
Vincent15mo ago
Got it! Thanks for clarifying. That means Alpine's $wire (in e.g. a Custom Field) will always refer the parent Livewire component, and that's how we can manipulate livewire state inside nested fields, yeah? So we might not need a nested Livewire component
awcodes
awcodes15mo ago
Well, it's all wired together, so you can update the state of other form components with $get and $set. If they are arrays you just have to traverse the array. But you're not technically wrong. You can also just use an Alpine component and bind the field's state to the alpine component, that should keep the state of the component in sync with the form's state. just feels like there might be some over complication going on here.
Vincent
Vincent15mo ago
me, a developer, overcomplicate things? impossible I have to read the docs more closely -- didn't know about $get and $set. FWIW I'm writing a wizard with a text input that's an autocomplete/search field. It hits an API on update and populates a radio group below with the results from the API call. I can start a new thread if I run into more hiccups, I know this one's getting a little long. Thanks for all your help!
Want results from more Discord servers?
Add your server