F
Filamentβ€’16mo ago
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; }...
Jump to solution
4 Replies
petrisorcraciun
petrisorcraciunβ€’16mo ago
return $this->evaluate($mask, [ 'mask' => app(TextInput\Mask::class), ]);
BuggerSee
BuggerSeeOPβ€’16mo ago
public function getMask(): ?Mask
{
$mask = new Mask();

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

return $this->evaluate($mask, [
'mask' => app(TextInput\Mask::class),
]);
}
public function getMask(): ?Mask
{
$mask = new Mask();

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

return $this->evaluate($mask, [
'mask' => app(TextInput\Mask::class),
]);
}
Like this? Does not work for me unfortunately
Solution
BuggerSee
BuggerSeeβ€’16mo ago
Needed to add this and it apparently works. Thanks!
public function hasMask(): bool
{
return true;
}
public function hasMask(): bool
{
return true;
}
petrisorcraciun
petrisorcraciunβ€’16mo ago
super πŸ™‚
Want results from more Discord servers?
Add your server