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.

Global Type with Tab(s) and Same Field Names Cause Mirroring Data

default discord avatar
f12057last year

Currently, I have a global type which has two tabs. Each tab has the same fields down to the name.



Example Code
export const foo: GlobalConfig = {
  slug: 'foo'
  fields: [
    {
      type: 'tabs',
      tabs: [
        {
          label: 'Tab One',
          description: 'description'
          fields: [
            {
              type: 'text',
              name: 'bar',
            }
          ]
        },
        {
          label: 'Tab Two',
          description: 'description'
          fields: [
            {
              type: 'text',
              name: 'bar',
            }
          ]
        }
      }
    ]
}


Issue

When I update data for Tab One -> 'bar' field then the Tab Two -> 'bar' field shows the same data and vice versa.



Question

Is there a way to have two tabs with same named fields that do not mirror each others data? I'd like to keep the same name because then I can keep the shape/labels/etc of each set of fields in a constants file.



Thanks for your help!



Arg per usual I did troubleshooting for awhile then asked a question and figured it out right after asking.



Info Gathered

Some (maybe all) fields including

tabs

has a property named

name

that acts as the unique identifier for that field. When using two tabs with identical field names the data mirrors each other as described because there was no

name

set on

tabs

to make each distinct.



Solution

Add distinct

name

field to each tab as such:



{
  type: 'tabs'
  tabs: [
   {
      name: 'foo',
      label: 'Foo'
   },
   {
      name: 'bar',
      label: 'Bar'
   }
  ]
}


Giving each tab it's own unique name will result in the data beneath it being nested under that identifier.

    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.