How to show/hide a component using actions in form?

As what the title said, I want to show or hide a specific component in the form builder but using the action not the toggle or checkbox.
Action::make('hide_upload')
->icon('heroicon-m-eye-slash')
->action(function () {
// how to hide or show specific component here inside the form?
});
Action::make('hide_upload')
->icon('heroicon-m-eye-slash')
->action(function () {
// how to hide or show specific component here inside the form?
});
Solution:
Use the action to set a property in the class and use that property value to determine whether to hide or show the component maybe?
Jump to solution
4 Replies
awcodes
awcodes5mo ago
Sorry, not following the use case. An action requires user interaction. What is the use case.
jaocero
jaoceroOP5mo ago
Hi @awcodes example here this is a custom form in a livewire component. Beside the message I want to add the action so that whenever a user wants to upload they will just click the action then show the upload component. It takes a lot of space so I want to hide or show it using action but not toggle or anything else
No description
Solution
Andrew Wallo
Andrew Wallo5mo ago
Use the action to set a property in the class and use that property value to determine whether to hide or show the component maybe?
jaocero
jaoceroOP5mo ago
I've got it working thank youu @Andrew Wallo
Forms\Components\Actions\Action::make('show_hide_upload')
->action(fn () => $this->showUpload = !$this->showUpload)
Forms\Components\Actions\Action::make('show_hide_upload')
->action(fn () => $this->showUpload = !$this->showUpload)
Want results from more Discord servers?
Add your server