@homecode/ui 4.28.0 → 4.28.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -11,7 +11,7 @@ import '../Button/Button.styl.js';
|
|
|
11
11
|
import './SubmitButtons/SubmitButtons.styl.js';
|
|
12
12
|
|
|
13
13
|
const Field = function Field(props) {
|
|
14
|
-
const { value, error, markEdited, isChanged, isTouched, clearMargins, component: Control = Input, className, onChange, onBlur, handleChange, handleBlur, children, ...controlProps } = props;
|
|
14
|
+
const { value, error, markEdited, isChanged, isTouched, clearMargins, component: Control = Input, className, onChange, onBlur, handleChange, handleBlur, children, disableErrorReporting, ...controlProps } = props;
|
|
15
15
|
const { name, isHidden } = controlProps;
|
|
16
16
|
const valField = typeof value === 'boolean' ? 'checked' : 'value';
|
|
17
17
|
const classes = cn(className, S.field, isHidden && S.hidden, clearMargins && S.clearMargins, markEdited && isChanged && S.changed);
|
|
@@ -31,12 +31,12 @@ const Field = function Field(props) {
|
|
|
31
31
|
[valField]: value,
|
|
32
32
|
onChange: handleFieldChange,
|
|
33
33
|
onBlur: handleFieldBlur,
|
|
34
|
-
error: isTouched && error?.message,
|
|
34
|
+
error: disableErrorReporting ? undefined : isTouched && error?.message,
|
|
35
35
|
});
|
|
36
36
|
return (jsxs("div", { className: classes, children: [jsx(Control, { ...controlProps }), children] }));
|
|
37
37
|
};
|
|
38
38
|
function Form(props) {
|
|
39
|
-
const { className, children, initialValues = {}, validationSchema, defaultDisabled = {}, defaultValues, markEdited, onInit, onChange, onSubmit, ...restProps } = props;
|
|
39
|
+
const { className, children, initialValues = {}, validationSchema, defaultDisabled = {}, defaultValues, markEdited, disableErrorReporting, onInit, onChange, onSubmit, ...restProps } = props;
|
|
40
40
|
const validationSchemaRef = useRef(validationSchema);
|
|
41
41
|
const defaultValuesRef = useRef({});
|
|
42
42
|
// Update default values helper
|
|
@@ -182,14 +182,13 @@ function Form(props) {
|
|
|
182
182
|
if (valuesRef.current[field] === val)
|
|
183
183
|
return;
|
|
184
184
|
const newValues = { ...valuesRef.current, [field]: val };
|
|
185
|
-
|
|
186
|
-
return;
|
|
185
|
+
onChange?.(newValues);
|
|
187
186
|
const isTouched = !compare(val, initialValues[field]);
|
|
188
187
|
setValue(field, val);
|
|
189
188
|
setFieldTouched(field, isTouched);
|
|
190
189
|
calcChanged(field, val);
|
|
191
190
|
validate();
|
|
192
|
-
}, [calcChanged, validate, initialValues]);
|
|
191
|
+
}, [calcChanged, validate, initialValues, onChange]);
|
|
193
192
|
const onBlurHandler = useCallback((name) => {
|
|
194
193
|
setFieldTouched(name, true);
|
|
195
194
|
}, []);
|
|
@@ -206,7 +205,7 @@ function Form(props) {
|
|
|
206
205
|
setIsLoading(false);
|
|
207
206
|
};
|
|
208
207
|
const FieldComponent = useRef((fieldProps) => {
|
|
209
|
-
const { name } = fieldProps;
|
|
208
|
+
const { name, disableErrorReporting: fieldDisableErrorReporting } = fieldProps;
|
|
210
209
|
const fullProps = {
|
|
211
210
|
...fieldProps,
|
|
212
211
|
value: valuesRef.current[name],
|
|
@@ -216,6 +215,7 @@ function Form(props) {
|
|
|
216
215
|
isTouched: touchedRef.current[name],
|
|
217
216
|
handleChange: (...args) => onChangeHandlerRef.current(...args),
|
|
218
217
|
handleBlur: (...args) => onBlurHandlerRef.current(...args),
|
|
218
|
+
disableErrorReporting: fieldDisableErrorReporting ?? disableErrorReporting,
|
|
219
219
|
};
|
|
220
220
|
if (validationSchemaRef.current?.[name]?.empty === false) {
|
|
221
221
|
fullProps.required = true;
|
|
@@ -265,7 +265,6 @@ function Form(props) {
|
|
|
265
265
|
if (onInit)
|
|
266
266
|
onInit(formAPI);
|
|
267
267
|
}, []);
|
|
268
|
-
console.log('FORM: initialValues', initialValues);
|
|
269
268
|
const classes = cn(S.root, className, isLoading && S.isLoading);
|
|
270
269
|
return (jsx("form", { className: classes, ...restProps, onSubmit: onSubmitHandler, children: children(formAPI) }));
|
|
271
270
|
}
|
|
@@ -48,6 +48,7 @@ export type Props = ComponentType & {
|
|
|
48
48
|
defaultDisabled?: FieldsFlags;
|
|
49
49
|
validationSchema?: FormValidationSchema;
|
|
50
50
|
markEdited?: boolean;
|
|
51
|
+
disableErrorReporting?: boolean;
|
|
51
52
|
children: (api: FormAPI) => ReactNode | ReactNode[];
|
|
52
53
|
onInit?: (api: FormAPI) => boolean | void;
|
|
53
54
|
onChange?: (values: FormValues) => void | boolean;
|
|
@@ -61,6 +62,7 @@ export type FieldProps = {
|
|
|
61
62
|
markEdited?: Props['markEdited'];
|
|
62
63
|
value: any;
|
|
63
64
|
isHidden: boolean;
|
|
65
|
+
disableErrorReporting?: boolean;
|
|
64
66
|
component?: (props: FormFieldProps) => ReactNode;
|
|
65
67
|
children?: ReactNode;
|
|
66
68
|
};
|