Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

how to add units to a number field

default discord avatar
megetronlast year
1

there is the following block:


export const RAMBlock: Block = {
  slug: 'ram-block',
  fields: [
    { name: 'type', type: 'text'},
    { name: 'capacity', type: 'number'},

  ],
};


i want to save capacity as number in database, but on the frontend i would expect graphql payload to return a formatted string {capacity: "16MB" }




i have some thoughts of changing the model to something like "capacity__MB" and so on the frontend to split the key but i guess it's not the best way to go.




any suggestions how to do this?

  • default discord avatar
    jarrod69420last year

    You could make a third text field, called

    formattedRAM

    and populate that field with an afterRead hook on the field itself. Then you would use siblingData to populate it.

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

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