© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
6 replies
BuggerSee

Custom Input use masking. (Money)

Hello, I want to create a custom input for money values. I just want to move this mask to the MoneyInput class, so i have less repeating code. Do i need to change the getMask function in order to do this?

MoneyInput::make('total_income')
                                            ->label('Total Income')
                                            ->prefix('$')
                                            ->mask(fn (TextInput\Mask $mask) => $mask
                                                ->numeric()
                                                ->thousandsSeparator(',')
                                                ->decimalSeparator('.')
                                                ->decimalPlaces(2)
                                            )
                                            ->numeric()
                                            ->required(),
MoneyInput::make('total_income')
                                            ->label('Total Income')
                                            ->prefix('$')
                                            ->mask(fn (TextInput\Mask $mask) => $mask
                                                ->numeric()
                                                ->thousandsSeparator(',')
                                                ->decimalSeparator('.')
                                                ->decimalPlaces(2)
                                            )
                                            ->numeric()
                                            ->required(),


This doesn't work:
class MoneyInput extends TextInput
{
    public function getMask(): ?Mask
    {
        $mask = new Mask();

        $mask->numeric()
            ->thousandsSeparator(',')
            ->decimalSeparator('.')
            ->decimalPlaces(2);

        return $mask;
    }
}
class MoneyInput extends TextInput
{
    public function getMask(): ?Mask
    {
        $mask = new Mask();

        $mask->numeric()
            ->thousandsSeparator(',')
            ->decimalSeparator('.')
            ->decimalPlaces(2);

        return $mask;
    }
}
Solution
Needed to add this and it apparently works. Thanks!
   public function hasMask(): bool
   {
       return true;
   }
   public function hasMask(): bool
   {
       return true;
   }
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Input masking
FilamentFFilament / ❓┊help
3y ago
Input masking
FilamentFFilament / ❓┊help
3y ago
Input Masking not rendering in Edit Mode
FilamentFFilament / ❓┊help
2y ago
Custom MoneyInput form field
FilamentFFilament / ❓┊help
2y ago