diff --git a/comps/form/typings.ts b/comps/form/typings.ts index 53965b8..fbd4224 100755 --- a/comps/form/typings.ts +++ b/comps/form/typings.ts @@ -5,6 +5,7 @@ import { FormHook } from "../form-old/utils/utils"; import { editorFormData } from "./utils/ed-data"; import { PropTypeText } from "./field/type/TypeText"; import { PropTypeRelation } from "./field/type/TypeRelation"; +import { getProp } from "../../.."; export type FMProps = { on_init: (arg: { fm: FMLocal; submit: any; reload: any }) => any; @@ -164,3 +165,34 @@ export const formType = (active: { item_id: string }, meta: any) => { }; }`; }; + +export const fieldType = (item: any, meta: any, fm: FMLocal) => { + const m = meta[item.id]; + if (m) { + const name = getProp(m.item, "name"); + const field = fm.fields[name]; + const def = fm.field_def[name]; + return ` + const field = null as unknown as { + status: "init" | "loading" | "ready"; + name: "${name}"; + type: "${field.type}"; + label: any; + desc: any; + prefix: any; + suffix: any; + width: any; + required: boolean; + focused: boolean; + disabled: boolean; + required_msg: any; + col?: GFCol; + Child: () => ReactNode; + input: Record & { + render: () => void; + }; + prop?: any; + } + `; + } +}; diff --git a/comps/form/utils/use-field.tsx b/comps/form/utils/use-field.tsx index b962860..2c47690 100755 --- a/comps/form/utils/use-field.tsx +++ b/comps/form/utils/use-field.tsx @@ -1,6 +1,6 @@ import { useLocal } from "@/utils/use-local"; -import { FMLocal, FieldInternal, FieldProp } from "../typings"; import { useEffect } from "react"; +import { FieldInternal, FieldProp } from "../typings"; export const useField = (arg: FieldProp) => { const field = useLocal>({ @@ -32,7 +32,7 @@ export const useField = (arg: FieldProp) => { const fm = arg.fm; useEffect(() => { - if (field.status === "init") { + if (field.status === "init" || !fm.fields[arg.name]) { field.status = "ready"; fm.fields[arg.name] = field; field.render(); diff --git a/comps/md/utils/typings.ts b/comps/md/utils/typings.ts index e010374..9a99d61 100755 --- a/comps/md/utils/typings.ts +++ b/comps/md/utils/typings.ts @@ -50,7 +50,7 @@ export type MDLocalInternal = { export type MDRef = { PassProp: any; child: any }; export type MDLocal = MDLocalInternal & { render: (force?: boolean) => void }; -export const MasterDetailType = `{ +export const MasterDetailType = `const md = { name: string; breadcrumb: { label: React.ReactNode; diff --git a/data.ts b/data.ts index bc7ecb1..d8ad1ee 100755 --- a/data.ts +++ b/data.ts @@ -3,6 +3,7 @@ export { FieldTypeRelation } from "./comps/form/field/type/TypeRelation"; export { Form } from "@/comps/form/Form"; export { Field } from "@/comps/form/field/Field"; export { formType } from "@/comps/form/typings"; +export { fieldType } from "@/comps/form/typings"; export { TableList } from "@/comps/list/TableList"; export { TableListType } from "@/comps/list/typings"; export { MasterDetail } from "@/comps/md/MasterDetail"; diff --git a/gen/gen_relation/gen_relation.ts b/gen/gen_relation/gen_relation.ts index 0a8706d..58768ce 100755 --- a/gen/gen_relation/gen_relation.ts +++ b/gen/gen_relation/gen_relation.ts @@ -35,6 +35,7 @@ export const gen_relation = async (modify: (data: any) => void, data: any) => { alert("Failed to generate! Primary Key not found. "); return; } + if (pk) { const code = {} as any; if (data["on_load"]) {