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
LeandroFerreira
LeandroFerreira14mo ago
Is bank account another field in the form?
astronomic
astronomic14mo ago
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?
LeandroFerreira
LeandroFerreira14mo ago
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.
astronomic
astronomic14mo ago
like the rule()?
LeandroFerreira
LeandroFerreira14mo ago
yes. If you want, send me a message in the pt-br channel yep
astronomic
astronomic14mo ago
Ok, thank you! I think I'm understanding now
LeandroFerreira
LeandroFerreira14mo ago
#pt-br
astronomic
astronomic14mo ago
thanks, If I see that it's getting complicated, I'll write to you there
LeandroFerreira
LeandroFerreira14mo ago
great!
astronomic
astronomic14mo ago
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.' ])); })
LeandroFerreira
LeandroFerreira14mo ago
Should work as well:
->exists(table: Persone::class, column: 'id', callback: function (Exists $rule, $get) {
return $rule->where('id', $get('persone_id'));
}),
->exists(table: Persone::class, column: 'id', callback: function (Exists $rule, $get) {
return $rule->where('id', $get('persone_id'));
}),