F
Filament9mo ago
\

Fail validation for multiple fields

Is it possible to simultaneously trigger validation failures for multiple fields when a specific condition is met in just one of those fields? While I'm familiar with the $fail closure function, I've only been able to get it to fail the field in which it's been called.
// First field
DatePicker::make('contract_start')
->rules([
fn (): Closure => function (string $attribute, $value, Closure $fail) {
if ($condition) {
$fail("Incorrect values passed.");
})
]),
// Second field
DatePicker::make('contract_end')
->rules([
fn (): Closure => function (string $attribute, $value, Closure $fail) {
if ($another_condition) {
$fail("Incorrect values passed.");
})
]),
// First field
DatePicker::make('contract_start')
->rules([
fn (): Closure => function (string $attribute, $value, Closure $fail) {
if ($condition) {
$fail("Incorrect values passed.");
})
]),
// Second field
DatePicker::make('contract_end')
->rules([
fn (): Closure => function (string $attribute, $value, Closure $fail) {
if ($another_condition) {
$fail("Incorrect values passed.");
})
]),
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server