implements a safer way to revert to original data if update policies fail
This commit is contained in:
@@ -1,10 +0,0 @@
|
||||
const flattenFilters = [{
|
||||
test: (_, value) => {
|
||||
const hasValidProperty = Object.prototype.hasOwnProperty.call(value, 'valid');
|
||||
const hasValueProperty = Object.prototype.hasOwnProperty.call(value, 'value');
|
||||
|
||||
return (hasValidProperty && hasValueProperty);
|
||||
},
|
||||
}];
|
||||
|
||||
export default flattenFilters;
|
||||
@@ -254,6 +254,9 @@ const Form = (props) => {
|
||||
|
||||
contextValue.validateForm = () => {
|
||||
return !Object.values(fields).some((field) => {
|
||||
if (field.valid === false) {
|
||||
console.log(field, ' is not valid');
|
||||
}
|
||||
return field.valid === false;
|
||||
});
|
||||
};
|
||||
|
||||
@@ -8,7 +8,7 @@ import { v4 as uuidv4 } from 'uuid';
|
||||
import withCondition from '../../withCondition';
|
||||
import Button from '../../../elements/Button';
|
||||
import reducer from '../rowReducer';
|
||||
import useForm from '../../Form/useForm';
|
||||
import useFormFields from '../../Form/useFormFields';
|
||||
import DraggableSection from '../../DraggableSection';
|
||||
import { useRenderedFields } from '../../RenderFields';
|
||||
import Error from '../../Error';
|
||||
@@ -67,7 +67,7 @@ const Flexible = (props) => {
|
||||
const dataToInitialize = initialData || defaultValue;
|
||||
const [rows, dispatchRows] = useReducer(reducer, []);
|
||||
const { customComponentsPath } = useRenderedFields();
|
||||
const { getDataByPath } = useForm();
|
||||
const { getDataByPath } = useFormFields();
|
||||
|
||||
const addRow = (index, blockType) => {
|
||||
const data = getDataByPath(path);
|
||||
|
||||
@@ -8,7 +8,7 @@ import Button from '../../../elements/Button';
|
||||
import DraggableSection from '../../DraggableSection';
|
||||
import reducer from '../rowReducer';
|
||||
import { useRenderedFields } from '../../RenderFields';
|
||||
import useForm from '../../Form/useForm';
|
||||
import useFormFields from '../../Form/useFormFields';
|
||||
import useFieldType from '../../useFieldType';
|
||||
import Error from '../../Error';
|
||||
import { repeater } from '../../../../../fields/validations';
|
||||
@@ -39,7 +39,7 @@ const Repeater = (props) => {
|
||||
const dataToInitialize = initialData || defaultValue;
|
||||
const [rows, dispatchRows] = useReducer(reducer, []);
|
||||
const { customComponentsPath } = useRenderedFields();
|
||||
const { getDataByPath } = useForm();
|
||||
const { getDataByPath } = useFormFields();
|
||||
|
||||
const path = pathFromProps || name;
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ const Upload = (props) => {
|
||||
const fieldType = useFieldType({
|
||||
path,
|
||||
required,
|
||||
initialData,
|
||||
initialData: initialData?.id,
|
||||
defaultValue,
|
||||
validate,
|
||||
});
|
||||
@@ -166,7 +166,9 @@ Upload.propTypes = {
|
||||
required: PropTypes.bool,
|
||||
readOnly: PropTypes.bool,
|
||||
defaultValue: PropTypes.string,
|
||||
initialData: PropTypes.shape({}),
|
||||
initialData: PropTypes.shape({
|
||||
id: PropTypes.string,
|
||||
}),
|
||||
validate: PropTypes.func,
|
||||
width: PropTypes.string,
|
||||
style: PropTypes.shape({}),
|
||||
|
||||
Reference in New Issue
Block a user