F
Filament16mo ago
xy

Custom form field - Check if state has a value?

I'm creating a custom form field which extends the Radio field. How can i check if state has a value in the view? The idea is to dynamically hide something if state has a value.
5 Replies
Patrick Boivin
Patrick Boivin16mo ago
I think $getState() should work
xy
xyOP16mo ago
Is there a method to set state also?
Patrick Boivin
Patrick Boivin16mo ago
Setting state from the view is a bit strange, but I think $state(...) should do it
xy
xyOP16mo ago
quick action to clear the state. Ill link it to a method in livewire component via wire:click @Patrick Boivin
public function clearState(): void {
$this->state(null);
}

<button wire:click="clearState()">
Clear
</button>
public function clearState(): void {
$this->state(null);
}

<button wire:click="clearState()">
Clear
</button>
Unable to call component method. Public method [clearState] not found on component
Unable to call component method. Public method [clearState] not found on component
Any idea why this does't work? Not sure why the above wasn't working so just ended up using $set
Patrick Boivin
Patrick Boivin16mo ago
There's not enough context, I need to see more code. But from what I see the button is probably outside of the livewire component you're trying to call this method on.
Want results from more Discord servers?
Add your server