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

default discord avatar
jankocian
9 months ago
8

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!

  • discord user avatar
    jesschow
    Payload Team
    9 months ago

    Hey @jankocian, 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
    jankocian
    9 months 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.

    image.png
    image.png
  • discord user avatar
    jesschow
    Payload Team
    9 months 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
    hzk1337
    8 months ago

    +1 for this problem 🙂

  • default discord avatar
    .redjoker
    3 months 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.

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.