Skip to content

Commit

Permalink
2.5.0 - handle field skipping when setting new form values
Browse files Browse the repository at this point in the history
  • Loading branch information
Tynik committed Jan 9, 2025
1 parent 812c4a7 commit 445c815
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 67 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@react-hive/honey-form",
"version": "2.4.0",
"version": "2.5.0",
"description": "The TS library to build the fully customized forms using React framework",
"keywords": [
"react",
Expand Down Expand Up @@ -33,7 +33,7 @@
"peerDependencies": {
"react": ">=18.0.0",
"react-dom": ">=18.0.0",
"@mdx-js/react": "3.0.1"
"@mdx-js/react": "3.1.0"
},
"devDependencies": {
"@testing-library/react": "16.1.0",
Expand All @@ -58,7 +58,7 @@
"prettier": "3.4.2",
"ts-jest": "29.2.5",
"ts-loader": "9.5.1",
"typescript": "5.7.2",
"typescript": "5.7.3",
"webpack": "5.97.1",
"webpack-cli": "6.0.1",
"html-webpack-plugin": "5.6.3"
Expand Down
112 changes: 56 additions & 56 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1718,6 +1718,7 @@ export const getNextFieldsState = <
});

processSkippableFields({ parentField, nextFormFields, formContext });

triggerScheduledFieldsValidations({
parentField,
fieldName,
Expand Down
26 changes: 18 additions & 8 deletions src/hooks/use-base-honey-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ export const useBaseHoneyForm = <
() => {
const nextFormFields = { ...formFields };

const formValues = getFormValues(nextFormFields);
if (isClearAll) {
resetAllFields(nextFormFields);
}
Expand All @@ -226,19 +227,28 @@ export const useBaseHoneyForm = <

const fieldConfig = nextFormFields[fieldName].config;

const isSkipField = checkIsSkipField({
parentField,
fieldName,
formContext,
formValues,
formFields: nextFormFields,
});

const filteredValue =
checkIfHoneyFormFieldIsInteractive(fieldConfig) && fieldConfig.filter
? fieldConfig.filter(values[fieldName], { formContext })
: values[fieldName];

const nextFormField = isValidate
? executeFieldValidator({
formContext,
fieldName,
formFields: nextFormFields,
fieldValue: filteredValue,
})
: getNextErrorsFreeField(nextFormFields[fieldName]);
const nextFormField =
!isSkipField && isValidate
? executeFieldValidator({
formContext,
fieldName,
formFields: nextFormFields,
fieldValue: filteredValue,
})
: getNextErrorsFreeField(nextFormFields[fieldName]);

nextFormFields[fieldName] = getNextSingleFieldState(nextFormField, filteredValue, {
formContext,
Expand Down

0 comments on commit 445c815

Please sign in to comment.