Skip to content

Commit

Permalink
issue with changing options on schema fields
Browse files Browse the repository at this point in the history
  • Loading branch information
joepuzzo committed Mar 9, 2022
1 parent f017f7d commit 623a1fa
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 4.5.7 (March 9th, 2022)

### Fixed

- issue with changing options on schema fields ( undefined would clobber defined values in option merge )

## 4.5.6 (March 8th, 2022)

### Fixed
Expand Down
17 changes: 12 additions & 5 deletions src/components/FormField.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import React, { useMemo, useEffect, useState } from 'react';
import {
computeFieldFromProperty,
getSchemaPathFromJsonPath,
checkCondition
checkCondition,
sanitize
} from '../utils';
import { ObjectMap } from '../ObjectMap';
import { useFormController } from '../hooks/useFormController';
Expand Down Expand Up @@ -98,7 +99,10 @@ const FormField = ({ name, schema, ...rest }) => {
// }

if (target === name) {
logger('Updating field props for', target);
logger(
`Updating field props for ${target}`,
computeFieldFromProperty(name, property)
);
setCondProp(computeFieldFromProperty(name, property));
}
};
Expand Down Expand Up @@ -127,9 +131,12 @@ const FormField = ({ name, schema, ...rest }) => {
const condProps = condProp.props;

// Lay those on top of existing ones
const newProps = { ...schemaProps, ...condProps, ...rest };

logger(`New Props for ${name}`, condProps);
const newSchemaProps = sanitize(schemaProps);
const newCondProps = sanitize(condProps);
const newProps = { ...newSchemaProps, ...newCondProps, ...rest };
logger(`Schema Props for ${name}`, newSchemaProps);
logger(`Cond Props for ${name}`, newCondProps);
logger(`New Props for ${name}`, newProps);
return newProps;
},
[condProp]
Expand Down
12 changes: 12 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,18 @@ export const generateValue = ({ fieldType, maskedValue, multiple, value }) => {
}
};

export const sanitize = obj => {
if (obj) {
const cleaned = JSON.parse(
JSON.stringify(obj, (key, value) => {
return value === undefined ? undefined : value;
})
);
return cleaned;
}
return obj;
};

/* -------------------------- Error Utils ----------------------------- */

export const yupToFormErrors = yupError => {
Expand Down

0 comments on commit 623a1fa

Please sign in to comment.