Turn formatStateUsing into a custom entry
I need the same formatStateUsing on many places across my admin panel so I was thinking that I should create a custom Entry / Input instead. I don't get how I should trigger the formatter in my custom entry. How would a simple entry look like with a custom formatter? Or are there any better solutions for this?
6 Replies
Just create a helper method somewhere in your app, like a Helpers class, then you can call it where ever you need it in
->formatStateUsing(fn ($state) => Helpers::customFormat($state))
Thank you. Yes, that would work. But it would be cleaner and more clear what it is with new field type.
Solution
then just create one.
I tried exactly like that, but the
formatStateUsing
callback is never called.
I only got it to work if I added a custom method that sets the formatStateUsing propertyyou have to pass the component and state into it. for example:
I figured it out now. Thanks a lot! π That was helpful π