F
Filament11mo ago
Anish

Disable Submit Button

I have a custom page with a simple form having one single checkbox button. I want to disable the submit button if the checkbox is not checked /accepted. Is there any easy way to achieve it? Thanks in advance for any help.
3 Replies
Tieme
Tieme11mo ago
use ->live() on the checkbog and ->disabled(fn(Get $get):bool => $get('field')) on the action
LeandroFerreira
LeandroFerreira11mo ago
public ?array $data = [];

public function mount(): void
{
$this->form->fill();
}

public function form(Form $form): Form
{
return $form
->schema([
Checkbox::make('checkbox_field')
->live(),
])
->statePath('data');
}
public ?array $data = [];

public function mount(): void
{
$this->form->fill();
}

public function form(Form $form): Form
{
return $form
->schema([
Checkbox::make('checkbox_field')
->live(),
])
->statePath('data');
}
<form wire:submit="create">
{{ $this->form }}

<x-filament::button :disabled="!$data['checkbox_field']" type="submit">
Submit
</x-filament::button>
</form>
<form wire:submit="create">
{{ $this->form }}

<x-filament::button :disabled="!$data['checkbox_field']" type="submit">
Submit
</x-filament::button>
</form>
Anish
AnishOP11mo ago
Thanks for your response. I will try it out
Want results from more Discord servers?
Add your server