From 74f37e2175fdb30b26ab265177b771a4fc8ec077 Mon Sep 17 00:00:00 2001 From: Aleksei Potsetsuev Date: Thu, 28 Mar 2024 23:00:18 +0800 Subject: [PATCH] CB-4776 fix: input default value handling --- .../src/FormControls/InputField/InputFieldState.tsx | 12 +++--------- .../src/FormControls/useFormStateControl.ts | 8 ++++---- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/webapp/packages/core-blocks/src/FormControls/InputField/InputFieldState.tsx b/webapp/packages/core-blocks/src/FormControls/InputField/InputFieldState.tsx index 3fdb281932..401968cd95 100644 --- a/webapp/packages/core-blocks/src/FormControls/InputField/InputFieldState.tsx +++ b/webapp/packages/core-blocks/src/FormControls/InputField/InputFieldState.tsx @@ -29,14 +29,8 @@ export const InputFieldState: InputFieldType = observer - ); + const defaultValue = rest.type === 'password' ? null : controlState.defaultStringValue; + + return ; }), ) as InputFieldType; diff --git a/webapp/packages/core-blocks/src/FormControls/useFormStateControl.ts b/webapp/packages/core-blocks/src/FormControls/useFormStateControl.ts index 7d7febcf41..436875f942 100644 --- a/webapp/packages/core-blocks/src/FormControls/useFormStateControl.ts +++ b/webapp/packages/core-blocks/src/FormControls/useFormStateControl.ts @@ -47,14 +47,14 @@ export function useFormStateControl, TKey ext value = value[name]; } - let stringValue: string | typeof value; - let defaultStringValue: string | typeof defaultValue; + let stringValue: string | typeof value | null; + let defaultStringValue: string | typeof defaultValue | null; if (mapToString) { stringValue = mapToString(value as any); defaultStringValue = mapToString(defaultValue as any); } else { - stringValue = isNotNullDefined(value) ? String(value) : ''; - defaultStringValue = isNotNullDefined(defaultValue) ? String(defaultValue) : ''; + stringValue = isNotNullDefined(value) ? String(value) : null; + defaultStringValue = isNotNullDefined(defaultValue) ? String(defaultValue) : null; } const hide = 'autoHide' in rest && !!rest.autoHide && presented === false;