How can I put an Select or TextInput in red when something happens?
I need that if the user chooses a client, for example, from a select, verify if that client has a bank account, if not, the input or select has to come out in red with a text informing that the bank account is missing. Is that possible?
11 Replies
Is bank account another field in the form?
Yes, it is part of the customers table, but the select is in the requests table, which contains client_id. Sorry for my english 😦
Você é brasileiro?
You could use the validation section: https://filamentphp.com/docs/2.x/forms/validation
Filament
Validation - Form Builder - Filament
The elegant TALL stack form builder for Laravel artisans.
like the rule()?
yes. If you want, send me a message in the pt-br channel
yep
Ok, thank you! I think I'm understanding now
#pt-br
thanks, If I see that it's getting complicated, I'll write to you there
great!
Solution by @Leandro Ferreira
->reactive()
->afterStateUpdated(function ($get, $component) {
$persone = Persone::find($get('persone_id'));
throw_if($persone->iban === null, ValidationException::withMessages([
$component->getStatePath() => 'Iban is required.'
]));
})
Should work as well: