diff --git a/package-lock.json b/package-lock.json index 391aa64..1ae9d1b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "rhf-conditional-logic", - "version": "0.0.1-alpha.3", + "version": "0.0.1-alpha.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "rhf-conditional-logic", - "version": "0.0.1-alpha.3", + "version": "0.0.1-alpha.4", "dependencies": { "react": "^18.2.0", "react-hook-form": "^7.47.0", diff --git a/package.json b/package.json index a8a9cf3..9225473 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rhf-conditional-logic", - "version": "0.0.1-alpha.3", + "version": "0.0.1-alpha.4", "main": "./dist/rhf-conditional-logic.cjs", "module": "./dist/rhf-conditional-logic.mjs", "exports": { diff --git a/src/index.ts b/src/index.ts index e03a89a..b4bc59e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -63,12 +63,12 @@ export function pruneHiddenFields< ); // Remove hidden values - const values = getValues(); + let values = getValues(); for (const fieldName in formFieldVisibility) { const isHidden = formFieldVisibility[fieldName as TFieldNames[number]] === false; if (isHidden) { - deleteByPathWithoutMutation(values, fieldName); + values = deleteByPathWithoutMutation(values, fieldName) as TFieldValues; } } return values; diff --git a/tests-e2e/mock-form/form.tsx b/tests-e2e/mock-form/form.tsx index 071f353..c93085e 100644 --- a/tests-e2e/mock-form/form.tsx +++ b/tests-e2e/mock-form/form.tsx @@ -34,8 +34,11 @@ export function Form() { formState: { errors }, } = formMethods; - const onSubmit = data => { - console.log("Successfully submitted", data as FormSchema); + const onSubmit = () => { + console.log( + "Successfully submitted", + pruneHiddenFields(conditions, formMethods.getValues) as FormSchema + ); }; const { otherCaterer: showOtherCaterer } = useConditionalLogic(