#requiredWithoutAll() validation being ignored

9 messages · Page 1 of 1 (latest)

vocal ocean
#

I'm using a Form Builder form in a regular Livewire component. Simple validations on the fields (required, email) work fine. But I have three fields with a requiredWithoutAll rule for the other two. So field1 has ->requiredWithoutAll('field2,field3'). These rules get ignored. No error messages and nothing in the logs. Just goes along and submits without any issue. I can put a secondary validation in the Livewire component itself which does catch them but it (a) makes for an ugly UX difference and (b) for some reason, custom error messages aren't working there. Any ideas why these rules aren't getting triggered?

deft pelicanBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

cunning solstice
#

I have the same issue, but with requiredWithout()

vocal ocean
# cunning solstice I have the same issue, but with `requiredWithout()`

I ended up having to put a specific validation for my three fields in the Livewire component method that the form uses for wire:submit. It works fine but I really don't like the UI switch. Still no clue why it doesn't work as documented but I couldn't spend any more time chasing it down.

cloud pivot
vocal ocean
# cloud pivot I know this is an old message but you need to put the requiredWithoutAll rule on...

Maybe it wasn't clear in my original message but it was on all three. ("I have three fields with a requiredWithoutAll rule for the other two.") But I only gave the example for field1. I had the requirement on each of them specifying the other two as the arguments. The end result I wanted is for at least one of them to be filled.

It's working okay with it on the component as described above but I'd love to have it working natively so if the way I had it was still wrong somehow, I'd appreciate any more information to get it all within the Filament form definition.

raw ginkgo
#

Can you share the code of the fields?

#

It’s possible that depending on the field types, one of them is always set to a value. But can’t be sure without seeing the relevant code.

vocal ocean
# raw ginkgo Can you share the code of the fields?

Here's the section involved. In short, I just want to make sure at least one phone number has a value but it lets me submit with them all empty.

        return Section::make('Contact Information')
            ->icon('heroicon-o-phone')
            ->columns(6)
            ->schema([
                         TextInput::make('email')
                             ->columnSpanFull()
                             ->email()
                             ->default(auth()->user()->email)
                             ->required(),

                         PhoneNumber::make('homePhone')
                             ->columnSpan(2)
                             ->databaseFormat(PhoneFormat::E164)
                             ->requiredWithoutAll('workPhone', 'cellPhone'),

                         PhoneNumber::make('workPhone')
                             ->columnSpan(2)
                             ->databaseFormat(PhoneFormat::E164)
                             ->requiredWithoutAll('homePhone', 'cellPhone'),

                         PhoneNumber::make('cellPhone')
                             ->columnSpan(2)
                             ->databaseFormat(PhoneFormat::E164)
                             ->requiredWithoutAll('homePhone', 'workPhone'),
                     ]);