RequiredWith and Without on same field?

I think it should work, but im probably missing something simple here or its simply not possible without custom rules. I have
TextInput::make('user.email')
->requiredWithout('user.phone')
->requiredWith(function ($get) {
return (bool)$get('send_welcome_email');
})
->email()
->rule(new UniqueForTenant(User::class, $recordId))
.....
TextInput::make('user.email')
->requiredWithout('user.phone')
->requiredWith(function ($get) {
return (bool)$get('send_welcome_email');
})
->email()
->rule(new UniqueForTenant(User::class, $recordId))
.....
and
Toggle::make('send_welcome_email')
->label('Send Welcome Email')
->reactive(),
Toggle::make('send_welcome_email')
->label('Send Welcome Email')
->reactive(),
. Should i be able to have both requirements? Right now Im the following error on submit:
array_map(): Argument #2 ($array) must be of type array, bool given on #file: "/Users/....../vendor/filament/forms/src/Components/Concerns/CanBeValidated.php"
array_map(): Argument #2 ($array) must be of type array, bool given on #file: "/Users/....../vendor/filament/forms/src/Components/Concerns/CanBeValidated.php"
Solution:
now the error actualyl makes sense. lol. Got it working with
->requiredWith(function ($get) {
return $get('send_welcome_email') ? ['send_welcome_email'] : [];
})
->requiredWith(function ($get) {
return $get('send_welcome_email') ? ['send_welcome_email'] : [];
})
...
Jump to solution
2 Replies
Mark Chaney
Mark ChaneyOP2y ago
oh, oops
Solution
Mark Chaney
Mark Chaney2y ago
now the error actualyl makes sense. lol. Got it working with
->requiredWith(function ($get) {
return $get('send_welcome_email') ? ['send_welcome_email'] : [];
})
->requiredWith(function ($get) {
return $get('send_welcome_email') ? ['send_welcome_email'] : [];
})
Want results from more Discord servers?
Add your server