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.

useAsTitle 'filename' for media collections does not seem to work

default discord avatar
jankocian2 years ago
5

Hey, I'd like to have filenames as titles in the Admin, instead of the ID - it makes more sense in the validation messages and provides overall better user experience.



admin: {
    useAsTitle: 'filename',
  },


According to the docs, this code in my

CollectionConfig

should work, but in reality, I'm stuck with the IDs. Any ideas? 🙂



Thanks a lot!

  • default discord avatar
    jessrynkar2 years ago

    Hey

    @930428018546049024

    , this works as intended when I replicate - where in the admin panel are you still seeing the media ID?


    Have you tried removing your

    /node_modules/.cache

    ?

  • default discord avatar
    jankocian2 years ago


    I did remove my

    node_modules/.cache

    yet still nothing... Examples in the screenshots above.



    Btw. changing useAsTitle to an actual alt field does work.

  • default discord avatar
    jessrynkar2 years ago
    oic

    - interesting, I'll have to dig deeper to see why you cannot access the filename in this scenario.



    Work around for now - create a field that duplicates the filename and point

    useAsTitle

    to it. Try this:


        {
          name: 'title',
          label: 'filename',
          type: 'text',
          admin: {
            readOnly: true,
            hidden: true,
          },
          hooks: {
            beforeChange: [
              ({ data }) => {
                return data.filename;
              }
            ],
          },
        },
  • default discord avatar
    hzk13372 years ago

    +1 for this problem 🙂

  • default discord avatar
    .redjoker2 years ago

    + 1 for this



    This appears to be related to the data in mongo. Starting with a fresh database got rid of the issue for me.

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.