requiredWithoutAll() doesn't seem to be working

I am attempting to use requiredWithoutAll() on a custom page. This is my condensed code: <?php namespace App\Filament\Pages; use App\Filament\Pages\Concerns\HasProfileSerializationAction; use Filament\Forms\Components\TextInput; use Filament\Pages\Page; use Filament\Schemas\Concerns\InteractsWithSchemas; use Filament\Schemas\Contracts\HasSchemas; use Filament\Schemas\Schema; use Livewire\Attributes\Url; class VetProfile extends Page implements HasSchemas { use InteractsWithSchemas; use HasProfileSerializationAction; #[Url] public ?int $memberId = null; protected string $view = 'filament.pages.vet-profile'; public function form(Schema $schema): Schema { return $schema ->components([ TextInput::make('a') ->requiredWithoutAll('b'), TextInput::make('b'), ]); } public function save() { // do nothing } } I would have expected that if I don't fill anything in and click Save, I would get an error on TextInput a, as TextInput b has not been filled in. I am actually trying to do this with checkboxes, which also does not work. Am I misunderstanding this or is there a bug?
Solution:
The issue I had is that $data = $this->form->getState(); needs to be called in save() for these validation mechanisms to take place.
Jump to solution
2 Replies
keiron
keironOP5d ago
(Latest version of Filament 4 and Laravel 12, all packages updated) I have also checked ->alpha() validation which doesn't run either. It seems that maybe no validation runs except for ->required() With the help of ChatGPT I managed to get ->alpha() working with this code. It's telling me my issue is something to do with my use of Schema vs Forms. I will try and get it working in my main code and report back. <?php namespace App\Filament\Pages; use Filament\Forms\Components\TextInput; use Filament\Forms\Concerns\InteractsWithForms; use Filament\Forms\Contracts\HasForms; use Filament\Pages\Page; class VetProfile extends Page implements HasForms { use InteractsWithForms; public ?array $data = []; protected string $view = 'filament.pages.vet-profile'; public function mount(): void { $this->form->fill(); // optional, but handy } // <-- no type hints here public function form($form) { return $form ->schema([ TextInput::make('a') ->label('Name') ->alpha() ->required(), ]) ->statePath('data'); } public function save(): void { $data = $this->form->getState(); // save it } }
Solution
keiron
keiron5d ago
The issue I had is that $data = $this->form->getState(); needs to be called in save() for these validation mechanisms to take place.

Did you find this page helpful?