From 15a37a2b27db59cfa67f1c5367b9615e73408319 Mon Sep 17 00:00:00 2001 From: Rizky Date: Fri, 5 Jul 2024 00:02:40 -0700 Subject: [PATCH] fix form --- comps/form/Form.tsx | 13 ++++++------- comps/form/field/type/TypeDropdown.tsx | 10 ++++++++++ comps/form/field/type/TypeInput.tsx | 3 +++ comps/form/typings.ts | 7 ++++++- comps/form/utils/use-field.tsx | 2 ++ 5 files changed, 27 insertions(+), 8 deletions(-) diff --git a/comps/form/Form.tsx b/comps/form/Form.tsx index cca1943..2e2b17b 100755 --- a/comps/form/Form.tsx +++ b/comps/form/Form.tsx @@ -58,7 +58,10 @@ export const Form: FC = (props) => { }); if (props.render_parent) { - fm.render = props.render_parent; + if (!fm.internal.original_render) fm.internal.original_render = fm.render; + fm.render = () => { + if (props.render_parent) props.render_parent(); + }; } useEffect(() => { @@ -141,11 +144,7 @@ export const Form: FC = (props) => { const toaster_el = document.getElementsByClassName("prasi-toaster")[0]; if (fm.status === "resizing") { - setTimeout(() => { - fm.status = "ready"; - fm.render(); - }, 100); - return null; + fm.status = "ready"; } return ( @@ -153,7 +152,7 @@ export const Form: FC = (props) => { onSubmit={(e) => { e.preventDefault(); e.stopPropagation(); - console.log("HALOO") + console.log("HALOO"); fm.submit(); }} ref={(el) => { diff --git a/comps/form/field/type/TypeDropdown.tsx b/comps/form/field/type/TypeDropdown.tsx index 96846d8..4cfc25d 100755 --- a/comps/form/field/type/TypeDropdown.tsx +++ b/comps/form/field/type/TypeDropdown.tsx @@ -43,6 +43,16 @@ export const TypeDropdown: FC<{ } else { local.options = res; } + local.render(); + value = + typeof arg.opt_get_value === "function" + ? arg.opt_get_value({ + fm, + name: field.name, + options: local.options, + type: field.type, + }) + : fm.data[field.name]; if ( field.type === "single-option" && field.required && diff --git a/comps/form/field/type/TypeInput.tsx b/comps/form/field/type/TypeInput.tsx index cf1f2ce..ce64d63 100755 --- a/comps/form/field/type/TypeInput.tsx +++ b/comps/form/field/type/TypeInput.tsx @@ -173,11 +173,14 @@ export const FieldTypeInput: FC<{ case "rich-text": return ; case "date": + console.log(field.min_date instanceof Date) return ( { diff --git a/comps/form/typings.ts b/comps/form/typings.ts index 334455e..e1b85fe 100755 --- a/comps/form/typings.ts +++ b/comps/form/typings.ts @@ -53,7 +53,7 @@ export type FieldProp = { required_msg: (name: string) => string | ReactElement; on_change: (arg: { value: any }) => void | Promise; PassProp: any; - disabled: ("y" | "n") | (() => true | false); + disabled: ("y" | "n") | (() => true | false); child: any; selection: "single" | "multi"; prefix: any; @@ -99,6 +99,8 @@ export type FieldProp = { gen_table?: string; gen_fields?: string; model_upload?: "upload" | "import"; + max_date?: any; + min_date?: any; }; export type FMInternal = { @@ -129,6 +131,7 @@ export type FMInternal = { timeout: ReturnType; done: any[]; }; + original_render?: () => void; }; props: Exclude; size: { @@ -171,6 +174,8 @@ export type FieldInternal = { fm: FMLocal; }) => void | Promise; prop?: any; + max_date?: FieldProp["max_date"]; + min_date?: FieldProp["min_date"]; }; export type FieldLocal = FieldInternal & { render: () => void; diff --git a/comps/form/utils/use-field.tsx b/comps/form/utils/use-field.tsx index df84154..7c957de 100755 --- a/comps/form/utils/use-field.tsx +++ b/comps/form/utils/use-field.tsx @@ -36,6 +36,8 @@ export const useField = ( required_msg: arg.required_msg, disabled: typeof arg.disabled === "function" ? arg.disabled : arg.disabled === "y", on_change: arg.on_change, + max_date: arg.max_date, + min_date: arg.min_date, }; if (field.status === "init" || isEditor) {