pods-framework / pods

The Pods Framework is a Content Development Framework for WordPress - It lets you create and extend content types that can be used for any project. Add fields of various types we've built in, or add your own with custom inputs, you have total control.
https://pods.io/
GNU General Public License v2.0
1.07k stars 264 forks source link

Block Editor Form Validation #7369

Open JoryHogeveen opened 1 month ago

JoryHogeveen commented 1 month ago

Description

This PR adds a useBlockEditor React Hook which will initialize by overriding the default savePost function of WordPress core. Based on the code by ACF. The order of overriding should not matter as we are returning the previous value if no validation errors occur, therefore we should be compatible with ACF and other plugins using the same method.

The hook is further used within the field wrapper component which handles validation. Through this component I can set the valid state and pass any error messages.

This PR will not add extra validation on the current system but will be compatible with any extras we add to the useValidation hook as it is merely using it's response messages.

It should create error messages at the top if you click save and will auto-trigger that message to show on the field itself as well. After validation it will also disable the save button until you've made the required changes.

Related GitHub issue(s)

Fixes #7343

Testing instructions

Just create a Pod with some required fields and test around by trying to save the post.

Screenshots / screencast

Changelog text for these changes

PR checklist

what-the-diff[bot] commented 1 month ago

PR Summary