F
Filament2y 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
I think $getState() should work
xy
xyOP2y ago
Is there a method to set state also?
Patrick Boivin
Setting state from the view is a bit strange, but I think $state(...) should do it
xy
xyOP2y 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
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.

Did you find this page helpful?