Skip to content

Commit

Permalink
formComponent fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jgespinosa10 committed Oct 10, 2024
1 parent fbc139a commit 5cdb022
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 36 deletions.
2 changes: 1 addition & 1 deletion packages/ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@teselagen/ui",
"version": "0.5.23-beta.20",
"version": "0.5.23-beta.21",
"main": "./src/index.js",
"type": "module",
"exports": {
Expand Down
78 changes: 43 additions & 35 deletions packages/ui/src/FormComponents/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import classNames from "classnames";
import { SketchPicker } from "react-color";
import { isNumber, noop, kebabCase, isPlainObject, isEqual } from "lodash-es";
import mathExpressionEvaluator from "math-expression-evaluator";
import React, { useContext, useEffect, useState } from "react";
import React, { useContext, useEffect, useMemo, useState } from "react";
import { Field, change } from "redux-form";
import "./style.css";
import {
Expand Down Expand Up @@ -162,8 +162,7 @@ const AbstractInput = ({
onDefaultValChanged && onDefaultValChanged(defaultValue, name, form);
onFieldSubmit && onFieldSubmit(defaultValue);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [defaultValue]);
}, [defaultValue, dispatch, form, name, onDefaultValChanged, onFieldSubmit]);

// if our custom field level validation is happening then we don't want to show the error visually
const showError =
Expand Down Expand Up @@ -975,35 +974,29 @@ export function generateField(component, opts) {
// asyncValidate,
...rest
}) => {
const component = compWithDefaultVal;

const input = useMemo(() => {
if (noRedux)
return {
input: {
onChange: rest.onChange || noop,
onBlur: rest.onBlur || noop,
value: rest.value,
name
}
};
return {};
}, [name, noRedux, rest.onBlur, rest.onChange, rest.value]);
const props = {
onFieldSubmit,
name,
...(noRedux && {
input: {
onChange: rest.onChange || noop,
onBlur: rest.onBlur || noop,
value: rest.value,
name
}
}),
component,
...input,
component: compWithDefaultVal,
...(isRequired && { validate: fieldRequired }),
isRequired,
noRedux,
...rest
};

// if (asyncValidate) {
// props = {
// ...props,
// asyncValidate,
// component: WrappedAddAsyncValidate,
// passedComponent: component
// };
// }

return <Field {...props} />;
};
}
Expand Down Expand Up @@ -1131,20 +1124,35 @@ export const withAbstractWrapper = (ComponentToWrap, opts = {}) => {
triggerGetDefault();
}, [generateDefaultValue || {}]);
// const asyncValidating = props.asyncValidating;
const defaultProps = {
...rest,
defaultValue: defaultValueFromBackend || defaultValueFromProps,
disabled: props.disabled || allowUserOverride === false,
readOnly: props.readOnly || isLoadingDefaultValue,
intent: getIntent({
showErrorIfUntouched,
meta: { touched, error, warning }
const defaultProps = useMemo(
() => ({
...rest,
defaultValue: defaultValueFromBackend || defaultValueFromProps,
disabled: props.disabled || allowUserOverride === false,
readOnly: props.readOnly || isLoadingDefaultValue,
intent: getIntent({
showErrorIfUntouched,
meta: { touched, error, warning }
}),
intentClass: getIntentClass({
showErrorIfUntouched,
meta: { touched, error, warning }
})
}),
intentClass: getIntentClass({
[
allowUserOverride,
defaultValueFromBackend,
defaultValueFromProps,
error,
isLoadingDefaultValue,
props.disabled,
props.readOnly,
rest,
showErrorIfUntouched,
meta: { touched, error, warning }
})
};
touched,
warning
]
);

// don't show intent while async validating
// if (asyncValidating) {
Expand Down

0 comments on commit 5cdb022

Please sign in to comment.