#Implementing Document Validation Status (3.0)

9 messages · Page 1 of 1 (latest)

ionic thorn
#

Is there a way to validate a document against a collection's schema (including both built-in and custom field validations) in a simple way? Essentially, I'm looking for a method that replicates the validation process that occurs when publishing a document, but without the actual save operation.

Essentially can you create a field that updates as drafts are saved?:

{
   name: 'isValid',
   type: 'checkbox',
   admin: {
      readOnly: true,
   },
 }

I understand that you can do beforeChange hook and implement custom validation logic, but I just want to validate in the same way that payload is doing it and it would be so redundant to rewrite out all of that logic.

Maybe there is a much more simple method that I am missing?

hallow plaza
#

I think this can be done with React Hooks

#

Specifically validateForm

#

Let me know if that helps

ionic thorn
#

Hmm, I'm not sure. If I'm reading this correctly it seems that this would just be for validation of form data and UI components. They don't seem provide a direct method to validate the entire document against the collection's schema.

#

I found this after scouring the code:

const validateDraftData =
    collectionConfig?.versions?.drafts && collectionConfig?.versions?.drafts?.validate

(packages/next/src/views/Document/index.tsx)

but I'm not yet if you could use this method within the config itself.

ionic thorn
#

Maybe my question is a problem with the wrong approach.

Really, I was attempting to create a publishing status / version control workflow to the admin dashboard.

If anyone has some example of how they do this in general that would be helpful.

I would like to easily know if a document item has been changed and if so know if it was a purposeful change that should be published etc. I could see a scenario where documents that get changed never get published and get lost in a large collection.