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!
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
?
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.
- 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;
}
],
},
},
+1 for this problem 🙂
+ 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
Discord
online
Get help straight from the Payload team with an Enterprise License.