TextEntry default configuration

How can I setup global configurations for the TextEntry. I want to add default date format and other properties,
TextEntry::make('updated_at')
->label('general.updated_at')
->dateTime('d/m/Y h:i')
TextEntry::make('updated_at')
->label('general.updated_at')
->dateTime('d/m/Y h:i')
Solution:
if you want all date times to use that format you can configure the Schema component. ```php Schema::configureUsing(function (Schema $schema): void { $schema->defaultDateTimeDisplayFormat('m/d/Y H:i');...
Jump to solution
5 Replies
Will Aguilar
Will AguilarOP2mo ago
When working with dates I think it tries to apply that to every single TextEntry. This is what I'm doing
TextEntry::configureUsing(function (TextEntry $entry): void {
$entry->dateTime('d/m/Y H:i');
});
TextEntry::configureUsing(function (TextEntry $entry): void {
$entry->dateTime('d/m/Y H:i');
});
And I get the following error:
Malformed UTF-8 characters, possibly incorrectly encoded
Malformed UTF-8 characters, possibly incorrectly encoded
Not doing anything special. Just trying to render the tradicional updated_at from records
awcodes
awcodes2mo ago
ah, do you only need it in a few places or do you want all dates in filament to have that format? if it's not global you can just create your own 'DateTimeTextEntry' etc the extends the 'TextEntry' and use that instead.
class DateTimeTextEntry extends TextEntry
{
protected function setUp(): void
{
parent::setUp();

$this
->label(...)
->dateTime('m/d/Y H:i');
}
}
class DateTimeTextEntry extends TextEntry
{
protected function setUp(): void
{
parent::setUp();

$this
->label(...)
->dateTime('m/d/Y H:i');
}
}
Solution
awcodes
awcodes2mo ago
if you want all date times to use that format you can configure the Schema component.
Schema::configureUsing(function (Schema $schema): void {
$schema->defaultDateTimeDisplayFormat('m/d/Y H:i');
});
Schema::configureUsing(function (Schema $schema): void {
$schema->defaultDateTimeDisplayFormat('m/d/Y H:i');
});
Will Aguilar
Will AguilarOP2mo ago
@awcodes you are the best thank you 🫶

Did you find this page helpful?