Add checkValidation and isValid methods to window.podsDFV #7064
Add checkValidation and isValid methods to window.podsDFV #7064Shelob9 wants to merge 24 commits into
Conversation
PR Summary
|
|
This PR is completed for #6898 Note: Does not prevent save when fields are invalid. |
#6898 Co-authored-by: Scott Kingsley Clark <lol@scottkclark.com>
4f6718b to
0e4e052
Compare
5b051b7 to
7d59e27
Compare
|
New TODO list:
|
|
@sc0ttkclark I am looking at how to show validation messages when saving and also how to block saving. Here are some notes for me and/ or you.
|
|
Something like this in //Track when post is being saved so we can trigger validation
const [isPostSaving,setIsPostSaving] = useState(false);
//subscribe to "core/core-editor" to track when post is being saved
useEffect( () => {
const editor = select( 'core/editor' );
const unsubscribe = subscribe( () => {
setIsPostSaving(editor.isSavingPost());
} );
//Clean up when component unmounts
return unsubscribe;
}, [select,subscribe,setIsPostSaving] );I tried to do this in const editor = storeSelect( 'core/editor' );
const isEditorSaving = editor.isSavingPost();
const isEditorSavingLocked = editor.isSavingLocked(); |
|
@Shelob9 Here's what I ended up having to do to workaround the bug with locking post saving (both when post has not yet been published and on subsequent saves which have slightly different timing): |
Description
Add checkValidation and isValid methods to window.podsDFV
What we need:
pods/ui/js/dfv/src/hooks/useValidation.js
Lines 4 to 5 in 6f79abd
needsRevalidatebool in store. Make it a dependency of this effect.pods/ui/js/dfv/src/hooks/useValidation.js
Lines 7 to 25 in 6f79abd
Related GitHub issue(s)
Fixes #6898
Testing
widow.PodsDFV.formIsValid()in console, expect falsewindow.PodsDFV.getValidationMessages()in console, expect to see messageswidow.PodsDFV.formIsValid()in console, expect truewindow.PodsDFV.getValidationMessages()in console, expect not to see messagesChangelog text for these changes
getValidationMessagesmethod to window.podsDFVformIsValidmethod to window.podsDFVPR checklist