@@ -600,51 +600,56 @@ window.PodsDFV = {
600
600
} ,
601
601
602
602
/**
603
- * Check if Pod being edited is valid .
603
+ * Get list of validation messages for a form (based on pod, item ID, and form counter) .
604
604
*
605
- * Returns array of validation Messages
606
- *
607
- * @param {string } pod Pod slug/name.
608
- * @param {int } itemId Object ID.
609
- * @param {int } formCounter Form index.
605
+ * @param {string|null } pod Pod slug/name. (Optional.)
606
+ * @param {int|null } itemId Object ID. (Optional.)
607
+ * @param {int|null } formCounter Form index. (Optional.)
610
608
*
611
- * @return {string[] } Array of validation messages
609
+ * @return {string[]|undefined } List of validation messages, or undefined if not found.
612
610
*/
613
- checkValidation ( pod , itemId , formCounter ) {
614
- const storeKey = createStoreKey (
611
+ getValidationMessages ( pod = null , itemId = null , formCounter = null ) {
612
+ const form = this . detectForm (
615
613
pod ,
616
614
itemId ,
617
- formCounter ,
618
- STORE_KEY_DFV
615
+ formCounter
619
616
) ;
620
617
621
- const stored = select ( storeKey ) ;
622
-
623
- // Store not found.
624
- if ( ! stored ) {
618
+ if ( 'undefined' === typeof form ) {
625
619
return undefined ;
626
620
}
627
- //dispatch toggleNeedsValidating
628
- dispatch ( storeKey ) . toggleNeedsValidating ( ) ;
629
- //select getValidationMessages
630
- const validationMessages = select ( storeKey ) . getValidationMessages ( ) ;
621
+
622
+ // Check validations.
623
+ dispatch ( form . storeKey ) . toggleNeedsValidating ( ) ;
624
+
625
+ // Get validation messages.
626
+ const validationMessages = form . stored . getValidationMessages ( ) ;
627
+
628
+ // Debug output for validation messages for now. @todo Remove this.
631
629
console . log ( { validationMessages } ) ;
630
+
632
631
return validationMessages ;
633
632
} ,
634
633
635
634
/**
636
- * Check if Pod being edited is valid.
635
+ * Check if the form is valid (based on pod, item ID, and form counter) .
637
636
*
638
- * @param {string } pod Pod slug/name.
639
- * @param {int } itemId Object ID.
640
- * @param {int } formCounter Form index.
637
+ * @param {string|null } pod Pod slug/name. (Optional.)
638
+ * @param {int|null } itemId Object ID. (Optional.)
639
+ * @param {int|null } formCounter Form index. (Optional.)
641
640
*
642
- * @return {boolean } True if valid, false if not.
641
+ * @return {boolean|undefined } True if valid, false if not, or undefined if not found .
643
642
*/
644
- isValid ( pod , itemId , formCounter ) {
645
- const errors = this . checkValidation ( pod , itemId , formCounter ) ;
646
- return ! errors . length ;
643
+ formIsValid ( pod = null , itemId = null , formCounter = null ) {
644
+ const validationMessages = this . getValidationMessages ( pod , itemId , formCounter ) ;
645
+
646
+ if ( 'undefined' === typeof validationMessages ) {
647
+ return undefined ;
648
+ }
649
+
650
+ return 0 === validationMessages . length ;
647
651
} ,
652
+
648
653
/**
649
654
* Initialize Pod data.
650
655
*
0 commit comments