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
Is bank account another field in the form?
astronomic
astronomicOP2y 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
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
astronomicOP2y ago
like the rule()?
LeandroFerreira
yes. If you want, send me a message in the pt-br channel yep
astronomic
astronomicOP2y ago
Ok, thank you! I think I'm understanding now
LeandroFerreira
#pt-br
astronomic
astronomicOP2y ago
thanks, If I see that it's getting complicated, I'll write to you there
LeandroFerreira
great!
astronomic
astronomicOP2y 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
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'));
}),
Want results from more Discord servers?
Add your server