Transform Text

default discord avatar
steprob
6 months ago
4

I am at a crossroads. The API returns me data in uppercase and lowercase, is there any way that the API returns me the data only in uppercase? It could be done from the Frontend, but the component I'm working on for some strange reason does not allow me to transform them to uppercase.

  • default discord avatar
    jarrod69420
    6 months ago

    You could use a beforeChange hook to uppercase the field before saving if you wanted to prevent future misalignments. You would need to write a small script to update the existing ones (ez to do).



    Or you could use a beforeRead hook that transforms the text before it’s returned.



    I would likely go with option 1 bc the compute would only need to be done on write, and never on read.

  • default discord avatar
    steprob
    6 months ago

    I understand, would you be so kind to provide an example of option 1 please

  • default discord avatar
    jarrod69420
    6 months ago

    Which part are you unsure of?

  • default discord avatar
    steprob
    6 months ago

    of how the beforeChange hook should be implemented

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.