14 Replies
Cool. What's the problem?
if i have the value as null then i want to change it to '-' but i can't
What's the problem you're running into?
What happens if you use:
->formatStateUsing(fn ($state): string => $state ?? '-')
i want a '-' at the arrow mark place in the picture but the code gave isn't working because the value of that place is
null
so formatStateUsing isn't working thereTry to remove the
->date('M d')
part and formatting the date inside your formatStateUsing
section
something like thatnot working bro
Are you sure that
$state
is null, and not an empty string?
In this:
->formatStateUsing(fn ($state): string => $state ?? '-')
If $state
is an empty string, it will return that instead. If so, the following should work
->formatStateUsing(fn ($state): string => filled($state) ? $state : '-')
->placeholder('-')
formatStateUsing
is not executed for null
values. Try ->placeholder()
as Leandro suggests or use ->getStateUsing()
TIL. Should that be PRd to the docs?
I'm referring to
formatStateUsing
not being called when a field is null
on initialisation, and that getStateUsing()
could be an alternative in those situations.
getStateUsing()
was in the v2 docs, but removed.
The docs for formatStateUsing
(in forms) only say that it's called when fill()
is called on the form, but not that it's only called on fields that will be have data to fill. And dehydrateStateUsing
is called on fields with a null
value.working Thanks @Leandro Ferreira and @Dennis Koch