pods
pods copied to clipboard
Add checkValidation and isValid methods to window.podsDFV
Description
Add checkValidation and isValid methods to window.podsDFV
What we need:
- [x] The two new methods
- [x] A way to get the validation messages in podsDFV
- Moving validation state out of useValidation hook's local state, and into a store will with action and selector can solve for this.
- https://github.com/pods-framework/pods/blob/6f79abdcfc79f5f06a136c08dc9e125c392fc607/ui/js/dfv/src/hooks/useValidation.js#L4-L5
- [x] A way to trigger validation of Pods fields without submitting form.
- Once in store, add a
needsRevalidate
bool in store. Make it a dependency of this effect. - https://github.com/pods-framework/pods/blob/6f79abdcfc79f5f06a136c08dc9e125c392fc607/ui/js/dfv/src/hooks/useValidation.js#L7-L25
- Once in store, add a
- [ ] prevent save when fields are invalid.
Related GitHub issue(s)
Fixes #6898
Testing
- Make pod have invalid state
- run
widow.PodsDFV.formIsValid()
in console, expect false - run
window.PodsDFV.getValidationMessages()
in console, expect to see messages - Make pod have valid state
- run
widow.PodsDFV.formIsValid()
in console, expect true - run
window.PodsDFV.getValidationMessages()
in console, expect not to see messages
Changelog text for these changes
- Added: New
getValidationMessages
method to window.podsDFV - Added: New
formIsValid
method to window.podsDFV - Fixed: Notice component, with two messages, used the same key, generating React warning.
PR checklist
- [x] I have tested my own code to confirm it works as I intended.
- [x] My code follows the WordPress Coding Standards.
- [x] My code follows the WordPress Inline Documentation Standards.
- [x] My code includes automated tests for PHP and/or JS (if applicable).
PR Summary
-
Updated Dependency Version The version of a dependency crucial for the functioning of our application has been updated. This improves the reliability and performance of our application's UI.
-
Added 'storeKey' A key named
storeKey
has been added to several components and objects in our application. This enables better data tracking and state management, leading to a more effective and reliable application. -
Dynamic 'key' Prop in 'Notice' Component The
key
prop in ourNotice
component now changes based on themessage
it houses. This provides unique identifiers to each unique message and improves handling and tracking performance. -
Improved Email Validation Our email validation function now checks if an entered value exists before applying the validation test, reducing unnecessary computation and potential error occurrences.
-
Validation Message Control The components are now equipped to update validation messages and validation needs state more effectively with the use of an enhanced
useValidation
hook. -
Form Validation Functions We have introduced new functions to check and retrieve validation messages for a form. This aids in user-feedback and form submission flow, improving user experience.
-
Validation State Management Our state management has been expanded to include validation message states and state change functionalities, ensuring smoother and more reliable validation experiences.
-
Enhanced Test Cases Updated and newly added test cases help in verifying the functionality and reliability of new actions related to the validation system. This ensures the robust stability of our updates.
This PR is completed for #6898
Note: Does not prevent save when fields are invalid.
New TODO list:
- [x] Initialize state in pod editor f651e069675e6cc9f55d43de65770ced763201d6
- [ ] Only show validation messages on submit
@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.
-
core/block/editor
data module aslockPostSaving
andunlockPostSaving
https://developer.wordpress.org/block-editor/reference-guides/data/data-core-editor/#lockpostsaving - In the classic editor, not sure how to block saving beside disable button with the JavaScript.
- I have already added
isValidating
and way to dispatch validation.- https://github.com/pods-framework/pods/blob/fd5e633ddc7b7e059a2c15cfbd9349a3ce18f4c6/ui/js/dfv/src/hooks/useValidation.js#L22-L26
- https://github.com/pods-framework/pods/blob/fd5e633ddc7b7e059a2c15cfbd9349a3ce18f4c6/ui/js/dfv/src/store/actions.js#L337-L351
Something like this in PodsDFVApp
could tell us if the post is being saved or not. This works.
//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 ConnectedFieldWrapper
using the withSelect
and could not get editor
to be defined:
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):
https://github.com/WordPress/gutenberg/pull/49811#issuecomment-1507692556