ソースを参照

add getSubmitValues to Context

Ivan Galakhov 4 年 前
コミット
3c5cf86236

+ 9 - 2
dashboard/src/components/porter-form/PorterFormContextProvider.tsx

@@ -30,6 +30,7 @@ interface ContextProps {
   onSubmit: () => void;
   onSubmit: () => void;
   dispatchAction: (event: PorterFormAction) => void;
   dispatchAction: (event: PorterFormAction) => void;
   validationInfo: PorterFormValidationInfo;
   validationInfo: PorterFormValidationInfo;
+  getSubmitValues: () => PorterFormVariableList;
   isReadOnly?: boolean;
   isReadOnly?: boolean;
 }
 }
 
 
@@ -376,7 +377,7 @@ export const PorterFormContextProvider: React.FC<Props> = (props) => {
   using functions for each input to finalize the variables
   using functions for each input to finalize the variables
   This can take care of things like appending units to strings
   This can take care of things like appending units to strings
  */
  */
-  const onSubmitWrapper = () => {
+  const getSubmitValues = () => {
     // we start off with a base list of the current variables for fields
     // we start off with a base list of the current variables for fields
     // that don't need any processing on top (for example: checkbox)
     // that don't need any processing on top (for example: checkbox)
     // the assign here is important because that way state.variable isn't mutated
     // the assign here is important because that way state.variable isn't mutated
@@ -411,7 +412,12 @@ export const PorterFormContextProvider: React.FC<Props> = (props) => {
       )
       )
     );
     );
     if (props.doDebug) console.log(Object.assign.apply({}, varList));
     if (props.doDebug) console.log(Object.assign.apply({}, varList));
-    props.onSubmit(Object.assign.apply({}, varList));
+
+    return Object.assign.apply({}, varList);
+  };
+
+  const onSubmitWrapper = () => {
+    props.onSubmit(getSubmitValues());
   };
   };
 
 
   if (props.doDebug) {
   if (props.doDebug) {
@@ -434,6 +440,7 @@ export const PorterFormContextProvider: React.FC<Props> = (props) => {
           error: isValidated ? null : "Missing required fields",
           error: isValidated ? null : "Missing required fields",
         },
         },
         onSubmit: onSubmitWrapper,
         onSubmit: onSubmitWrapper,
+        getSubmitValues,
       }}
       }}
     >
     >
       {props.children}
       {props.children}