F
Filament9mo ago
Hemith

Assert for custom form validation values

An example would be from the filament docs:
TextInput::make('slug')->rules([
function () {
return function (string $attribute, $value, Closure $fail) {
if ($value === 'foo') {
$fail('The :attribute is invalid.');
}
};
},
])
TextInput::make('slug')->rules([
function () {
return function (string $attribute, $value, Closure $fail) {
if ($value === 'foo') {
$fail('The :attribute is invalid.');
}
};
},
])
How can I assert for this particular validation when testing forms? I'm not sure what name to use.
Solution:
Got it. I could output the errors with
$component->errors();
$component->errors();
...
Jump to solution
2 Replies
Hemith
Hemith9mo ago
If that is not possible, is it possible to output all errors for a component?
$component = livewire(CreateHorseShare::class)
->fillForm([
'user_id' => $user->id,
'horse_id' => $horse->id,
'quantity' => 11,
])
->call('create')
->assertHasFormErrors([
'quantity' => 'required'
]);
$component = livewire(CreateHorseShare::class)
->fillForm([
'user_id' => $user->id,
'horse_id' => $horse->id,
'quantity' => 11,
])
->call('create')
->assertHasFormErrors([
'quantity' => 'required'
]);
For this, how can i output all errors for $compnent?
Solution
Hemith
Hemith9mo ago
Got it. I could output the errors with
$component->errors();
$component->errors();
I can then check the validation error I want from there.