plone / volto

React-based frontend for the Plone Content Management System
https://demo.plone.org/
MIT License
446 stars 606 forks source link

Extensible validation support in Volto forms #6181

Closed sneridagh closed 1 month ago

sneridagh commented 1 month ago

Supersedes #6161 Refactored and re-document for clarity and simplicity from it.

@stevepiercy I think now it's the good one. I'm more satisfied with this one now. I will review myself again, but I think it's ready for check.

@davisagli I've refactored it a bit after talking to @robgietema in lieu of clarity and simplicity. Also reflected it in the docs too. Decisions I made, we can talk about it:

Create an API for registerUtility

I think this is much more cleaner and fixes the thing you've mentioned in the other PR, for the "trying to push the square shaped piece in the circle shape hole". Also, I took it from a previous conversation last week with @ericof but that's another story. TL;DR: it was about the convenience of having an API that does and registers things for you, whatever it is, if it's a widget or a view, or other thing where you should "touch" and manually set things in different places. This makes much more sense to me now, with the current shape.

It will also make sense in other scenarios where I think we will need such "named utilities", eg. in other frameworks, having utility helpers, like flattenToAppUrl, globally, then ask for them in a named way.

Using the format property from JSON schema specs

@robgietema pointed me out to this one, I'm using the default property for defining named validators as defined in the spec.

I still have to cleanup, will continue working polishing this a bit.


📚 Documentation preview 📚: https://volto--6181.org.readthedocs.build/

netlify[bot] commented 1 month ago

Deploy Preview for plone-components canceled.

Name Link
Latest commit d50cda024c5bde3a2a3cf9db8d01db6179287757
Latest deploy log https://app.netlify.com/sites/plone-components/deploys/66a8fe6df1fbda00084b2318
sneridagh commented 1 month ago

@davisagli @stevepiercy I think I went through all the suggestions, let me know if I left something!

tiberiuichim commented 1 month ago

Just to continue on my though on on-offs from the previous PR: I could implement a generic validator called customFunction, which reads the field definition from schema, finds a validate function in the schema and uses that for actual implementation. So I can have my "one-off" validation helper closer to the schema.

sneridagh commented 1 month ago

@tiberiuichim yeah, I think you could do that already with the current implementation. However, that would only work with not serializable blocks defined in code.

sneridagh commented 1 month ago

@tiberiuichim I implemented your blocksErrors prop suggestion.

sneridagh commented 1 month ago

@ichim-david done.

sneridagh commented 1 month ago

Merging! Thanks to all for the effort and for having this done!