-
Notifications
You must be signed in to change notification settings - Fork 13
Duplicating an item doesn't generate new ID #143
Comments
Hi @henrikwirth, thanks for opening this issue! It looks like there's a 'prepublish' event we can hook into to generate a uuid for a field. I think this could potentially solve this issue: This repo is quite outdated so I'm hesitate to dive back in, if you want to take a crack at setting something up (a new widget, or an update to this one) I'm happy to assist with any issues you might run into! |
I think I might have found a way. There is a |
CMS.registerEventListener({
name: "preSave",
handler: ({ entry }) => {
const data = entry.get("data");
if (entry.get("newRecord")) {
return data.set("id", "test-1234");
}
},
}); Not sure how we would access the Control Object to generate the ID according to the props. Any idea? |
Currently the generate function is coded within the React component that drives the input: netlify-cms-widgets/packages/widget-id/src/control.tsx Lines 26 to 39 in 67ac5d4
I think it'd be good to extract it out into a util function & export it |
Hi there, thanks for creating these widgets, I think NetlifyCMS is lacking behind with lots of things for sure.
I am using the ID Widget to generate unique IDs for collection items. Now the issue I am running into is that once I duplicate one of the items it copies the ID field too. Since it is supposed to be the unique identifier obviously this causes issues.
2 options i see:
regenerate
directly once someone duplicates an item?Regenerate
Button next to the ID field to do this manually?I'd be happy to help with a PR, but I since I never wrote a Widget I am not well aware of the possibilities.
The text was updated successfully, but these errors were encountered: