Is it possible to create a data collection as an array of strings instead of an array of objects wit

default discord avatar
juliandm1995last year
7

Is there a way to generate a data collection that is an array of strings, for example:



interests: ["interest one", "interest two", ...]

instead of an array of objects as it currently is:



interests: [{"id": "1234", "value": "interest one"}, {"id": "1235", "value": "interest two"}, ...]

?

  • default discord avatar
    notchrlast year

    How about JSON?

    https://payloadcms.com/docs/fields/json


    There may be a better way than JSON



    But alternatively, you could hook into the field hooks



    https://payloadcms.com/docs/hooks/fields


    And either format the field, or save to a field that is formatted as you want

  • default discord avatar
    httpslinuslast year

    Is there a reason to not just use


    interests.map(i => i.value);

    in your frontend to receive an array of strings?

  • discord user avatar
    jmikrut
    last year

    i agree with everything above, but one other note, we are planning to add

    hasMany: true

    to the

    text

    field at some point in the future as well, which will allow for an array of strings



    but right now we don't support that

  • default discord avatar
    gokulsck4 months ago

    Hi @jmikrut any update on the development of this feature?

  • discord user avatar
    jmikrut
    4 months ago

    not yet, but it is supported on the

    number

    field and it could be a good PR to make that just follows along with what the

    number

    field supports

  • default discord avatar
    gokulsck4 months ago

    Any ETA on this change?

  • discord user avatar
    jmikrut
    4 months ago

    it's a good question, let me add it to the roadmap officially so we can track it / work toward it



    how do you feel about building it? i could point you in the right direction



    otherwise it might take us 1-2 months



    https://github.com/payloadcms/payload/discussions/4393
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.