how to add units to a number field

default discord avatar
4 months ago

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
    4 months ago

    You could make a third text field, called


    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!


Connect with the Payload Community on Discord



Can't find what you're looking for?

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