I have a slug field auto tracking file name in my Media collection.
I used documentInfo to tell if I'm creating a new media or editing an existing one and disabled edit for the slug when editing. (Modifying slug is not allowed
const documentInfo = useDocumentInfo(); const isUpdateRef = useRef(!!documentInfo.id);
But now it's not working when I open the modal form inside an article.
I'd like to know is there any way to get the documentInfo of current form instead of current page?
For now, what I can find is to use the formRef to find the closest
const form = useForm(); const documentInfo = useDocumentInfo(); const isUpdateRef = useRef( !!documentInfo.id && !form.formRef.current.closest('dialog') );
Nice work figuring out a solution. I'd like to see Payload have a built-in solution for handling multiple forms from the provider. I'm adding the "enhancement" label so we can revisit this problem later.
You can use
useEditDepth to determine how deeply nested the form is
It's not "officially" exported yet but you can access it directly from
dist in the meantime if you'd like. Also, @Stupidism we would be happy to accept a PR that adds
useEditDepth to our