F
Filament15mo ago
jouni.i

TextColumn formatState if state if empty

how can i set default value if valid_from is empty? I would like to set the value to "not set"?
10 Replies
Patrick Boivin
Patrick Boivin15mo ago
What is "not set" in this context? NULL in the database?
jouni.i
jouni.iOP15mo ago
yes we convert old laravel project to use filaments.. and old database is lot off rows where valid_from is null, we need inform users somehow about this..
Patrick Boivin
Patrick Boivin15mo ago
Something like this?
->formatStateUsing(function ($state) {
if (is_null($state)) {
return 'Something';
}

return $state;
})
->formatStateUsing(function ($state) {
if (is_null($state)) {
return 'Something';
}

return $state;
})
ZedoX
ZedoX15mo ago
->default('not set') ?
Patrick Boivin
Patrick Boivin15mo ago
Not sure if default() applies in the context of a List but something to try
cheesegrits
cheesegrits15mo ago
So in this case, it's a choice between default() and placeholder(). Personally I would go for placeholder().
ZedoX
ZedoX15mo ago
Ooo i didn't know about placeholder, time to refactor my code
Patrick Boivin
Patrick Boivin15mo ago
Same, this is pretty cool! Thanks @Hugh Messenger
jouni.i
jouni.iOP15mo ago
Thx all

Did you find this page helpful?