how to add units to a number field

default discord avatar
megetron
last week
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?

  • discord user avatar
    Jarrod
    Payload Team
    last week

    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.

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.