© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•17mo ago•
1 reply
daregu

Issue with Dynamic Class Application in `TextInput::make`

Hello, I’m encountering an issue with dynamically applying a class in the
TextInput::make
TextInput::make
component of my project.

Here’s the code I’m using:

TextInput::make('result')
    ->numeric()
    ->required()
    ->live()
    ->extraInputAttributes(function (Examen $record, Get $get, $state) {
        $positivo = false;
        $class = $positivo ? 'bg-green-100' : 'bg-red-100';
        dump($class); // For debugging
        return ['class' => (string) $class];
    }, true)
TextInput::make('result')
    ->numeric()
    ->required()
    ->live()
    ->extraInputAttributes(function (Examen $record, Get $get, $state) {
        $positivo = false;
        $class = $positivo ? 'bg-green-100' : 'bg-red-100';
        dump($class); // For debugging
        return ['class' => (string) $class];
    }, true)


The problem is that the class is not applied correctly when it is evaluated dynamically based on the
$positivo
$positivo
variable.

However, when I use a static class like this:

return ['class' => 'bg-red-600'];
return ['class' => 'bg-red-600'];


It works perfectly. But when I try to dynamically assign the class, it seems that the appropriate class is not applied.

Does anyone have any ideas why this happens or how to resolve it?

Thanks in advance for your help!
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Dynamic form with TextInput's
FilamentFFilament / ❓┊help
3y ago
Dynamic TextInput inside array result ?
FilamentFFilament / ❓┊help
3y ago
dynamic Use $class;
FilamentFFilament / ❓┊help
3y ago
Losing focus on TextInput class in actions form.
FilamentFFilament / ❓┊help
3y ago