Discussion on custom document actions not triggering validation in Sanity.io
33 replies
Last updated: Mar 1, 2022
E
anyone know why a document would allow to be published even though it has validation on it that was not succeeded?
Feb 15, 2022, 1:39 AM
R
Are you possibly using
Rule.warning()instead of
Rule.required()?
Feb 15, 2022, 4:40 PM
E
No they are all using required with an
.error()associated with each
Feb 15, 2022, 4:41 PM
R
Can you share the schema so I can try to replicate?
Feb 15, 2022, 4:42 PM
E
yes
Feb 15, 2022, 5:40 PM
E
E
yes
Feb 15, 2022, 5:40 PM
E
should i be using document level validation instead rather than field validation?
Feb 15, 2022, 5:40 PM
R
Your validation looks right! It looks like you've specified some custom document actions. What do those look like?
Feb 15, 2022, 5:52 PM
E
yes good catch, i am using the document actions from the workflow demo from sanity, so have a "request review" action, etc. But i still shouldnt be able to use that action, nor should i be able to publish until all validation has been satisfied, correct?
Feb 15, 2022, 5:59 PM
E
E
heres that request review action: https://github.com/BMW-CCA-PSR/bmwccapsr-website-gatsby/blob/d6d2958cf9f6ab9f69034[…]aba4/studio/src/documentActions/workflow/RequestReviewAction.js
and the publish action:
https://github.com/BMW-CCA-PSR/bmwccapsr-website-gatsby/blob/d6d2958cf9f6ab9f69034[…]3cb567aba4/studio/src/documentActions/workflow/PublishAction.js
and the publish action:
https://github.com/BMW-CCA-PSR/bmwccapsr-website-gatsby/blob/d6d2958cf9f6ab9f69034[…]3cb567aba4/studio/src/documentActions/workflow/PublishAction.js
Feb 15, 2022, 6:01 PM
E
im also looking at the document actions api page and i dont see anything explictly about validation wrt the execution of actions, is that something i need to do? https://www.sanity.io/docs/document-actions-api
Feb 15, 2022, 6:06 PM
J
I've just noticed this exact same behaviour. There's no mention of the developer having to handle validation manually if using custom document actions, so I'm not sure if this was always the case and it's not documented (which a little scary to be honest) or something gone wrong in a recent update.
Feb 15, 2022, 7:54 PM
E
hi
user M
im sorry to ping as i know you have this marked as a ticket and are tracking it as such, but any update here? Is this a bug or are we perhaps not doing something to enable the validation checks on custom document actions?Feb 16, 2022, 3:55 PM
E
any update
Feb 18, 2022, 3:45 AM
J
Hey
user M
, any news about this please? 😊Feb 20, 2022, 9:10 AM
E
also interested in an update
Feb 20, 2022, 9:12 AM
J
user M
should we open an issue on GitHub, is it not expected behaviour? Sorry for nagging but my client blew up something because the usual validation didn't kick in after I added a custom action.Feb 23, 2022, 12:58 PM
R
Can you confirm if this stopped working or if validation never worked after implementing a custom document action. Trying to narrow this down.
Feb 23, 2022, 5:51 PM
J
I don't know if I can tell you that. I implemented the custom action on the 23rd January, and I noticed the validation didn't kick in when my client published something with missing fields the day I replied to this message. Other items were published in the meantime, but to the best of my knowledge not with missing fields.
Feb 23, 2022, 10:30 PM
E
I also have a client who is passing garbage to my frontend and not understanding the issue as the visual validation is failing yet still letting them publish. I added my custom actions around mid-January as well (will have to check commits to see exact date).
Feb 23, 2022, 10:55 PM
E
I would +1 an issue created on GitHub as this appears to be broken or poorly documented functionality.
user M
do you have an example or testing that shows a custom document action is actually preventing publication of a document that is failing validation? I can also offer a zip package or GitHub link to my project’s studio config that you can download and start studio locally with. Feb 23, 2022, 10:58 PM
E
I would +1 an issue created on GitHub as this appears to be broken or poorly documented functionality.
user M
do you have an example or testing that shows a custom document action is actually preventing publication of a document that is failing validation? I can also offer a zip package or GitHub link to my project’s studio config that you can download and start studio locally with. Feb 23, 2022, 10:58 PM
R
Can you try adding this hook to your document action?
Feb 24, 2022, 4:10 PM
E
to each document action?
Mar 1, 2022, 2:58 AM
E
or just the publish/request review ones
Mar 1, 2022, 2:58 AM
E
its every action i need validation on it seems, thank you
user M
for looking into this.Mar 1, 2022, 3:25 AM
E
And also, if i could ask one more question from a best practices perspective, there really is no "isValid" function, but the way i am getting that as a boolean in order to flip the button state from disabled to enabled is doing something like this:
disabled: markers.length > 0 ? true : false,
Mar 1, 2022, 3:27 AM
E
this works but is this best from you opinion?
Mar 1, 2022, 3:28 AM
R
That's probably the way I'd go about it, as well.
Apologies that it took so long to find this hook. I mean, I work for Sanity and it took me a while to find, so it would be impossible for folks who don't have resources I do. It really should be included with the Document Actions documentation. We'll work on getting an example of using this added in.
Apologies that it took so long to find this hook. I mean, I work for Sanity and it took me a while to find, so it would be impossible for folks who don't have resources I do. It really should be included with the Document Actions documentation. We'll work on getting an example of using this added in.
Mar 1, 2022, 5:56 PM
E
Thank you so much Racheal, really helped me solve a big gap in our production workflow!
Mar 1, 2022, 8:00 PM
R
Very happy we finally got there 🙂
Mar 1, 2022, 8:01 PM
J
Hey guys, I've also done what Evan has and used a ternary on the
Thanks for the updates Racheal!
disabledproperty. It really should be mentioned that the default validation doesn't kick in with custom actions though, just a little footnote to save us from our clients tendencies to publish garbage 😁
Thanks for the updates Racheal!
Mar 1, 2022, 9:22 PM
Sanity– build remarkable experiences at scale
The Sanity Composable Content Cloud is the headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.