F
Filamentβ€’16mo ago
Vincent

TextColumn placeholder empty

Hi! I've got an app I just upgraded from v2 to v3. I've got most of the kinks worked out, but one small thing is bugging me: ->placeholder seems to not do much. Here's the column:
TextColumn::make('cost_usd')
->placeholder('In progress')
->label('Cost')
->formatStateUsing(
fn (float $state): string => '$' . number_format($state, 2)
),
TextColumn::make('cost_usd')
->placeholder('In progress')
->label('Cost')
->formatStateUsing(
fn (float $state): string => '$' . number_format($state, 2)
),
The cost_usd attribute is a nullable float (😬). formatStateUsing here works fine, and the column in the resulting table looks correct...except if the value is null. placeholder doesn't seem to make a difference. The table is in a custom widget and otherwise works great. Am I missing something?
Solution:
I think this is a known bug and on the radar.
Jump to solution
9 Replies
Hotcat
Hotcatβ€’16mo ago
I’m not sure why the placeholder has no effect, but try this way:
TextColumn::make('cost_usd')
->label('Cost')
->formatStateUsing(
fn (?float $state): string => $state ? '$' . number_format($state, 2) : 'In progress'
),
TextColumn::make('cost_usd')
->label('Cost')
->formatStateUsing(
fn (?float $state): string => $state ? '$' . number_format($state, 2) : 'In progress'
),
Or this one:
TextColumn::make('cost_usd')
->placeholder('In progress')
->label('Cost')
->money('usd'),
TextColumn::make('cost_usd')
->placeholder('In progress')
->label('Cost')
->money('usd'),
Probably placeholder applies after formatStateUsing, since there always remains a dollar sign, so it cannot be considered empty and the placeholder does not display
Solution
Dennis Koch
Dennis Kochβ€’16mo ago
I think this is a known bug and on the radar.
Vincent
VincentOPβ€’16mo ago
You know what's weird? I was using that exact ternary before the upgrade and it worked; now, though, the cell is still blank even if the short function returns a different string. I'd thought the same thing re: the string format never truly being empty, but even just returning $state with the placeholder doesn't do the trick. The money method is cool, didn't know about it! Placeholder still blank though. Ah that makes sense! Hadn't found any similar issues on github, must have just missed it. Let me know if I can help reproduce or debug!
Salah Kanjo
Salah Kanjoβ€’16mo ago
GitHub
placeholder() not working on Relationship / TextColumn::make('relat...
Package filament/filament Package Version v3.0-stable Laravel Version 10.10 Livewire Version No response PHP Version 8.2.7 Problem description TextColumn::make('relationship.column') ->p...
Salah Kanjo
Salah Kanjoβ€’16mo ago
Try using default
Vincent
VincentOPβ€’16mo ago
Thanks for the suggestion, I didn't know about default. default and placeholder feel semantically different, though: default provides a default value, which then gets passed to any formatters. So, doing the following:
TextColumn::make('cost_usd')
->label('Cost')
->default('In progress')
->money('usd'),
TextColumn::make('cost_usd')
->label('Cost')
->default('In progress')
->money('usd'),
results in an exception, because money requires a number, not a string -- but In progress is a string.
Salah Kanjo
Salah Kanjoβ€’16mo ago
Placeholder meant for form fields like TextInput and SelectInput etc..
Vincent
VincentOPβ€’16mo ago
Yep I saw that in your issue -- maybe the docs just need to be updated? Docs make it seem like placeholder can be used instead of the ternary I was using before, but I guess not. Anywho -- thank you for your suggestion!
Salah Kanjo
Salah Kanjoβ€’16mo ago
You're welcome!
Want results from more Discord servers?
Add your server