diff --git a/comps/form/Form.tsx b/comps/form/Form.tsx index 2e2b17b..d46e86f 100755 --- a/comps/form/Form.tsx +++ b/comps/form/Form.tsx @@ -160,7 +160,10 @@ export const Form: FC = (props) => { if (!ref.current.el) { ref.current.el = el; ref.current.rob.observe(el); - fm.status = "resizing"; + if (fm.status === "ready") { + fm.status = "resizing"; + fm.render(); + } } } }} diff --git a/comps/form/field/type/TypeDropdown.tsx b/comps/form/field/type/TypeDropdown.tsx index 4cfc25d..8c42678 100755 --- a/comps/form/field/type/TypeDropdown.tsx +++ b/comps/form/field/type/TypeDropdown.tsx @@ -13,6 +13,7 @@ export const TypeDropdown: FC<{ loaded: false, options: [] as { value: string; label: string; data: any }[], }); + let value = typeof arg.opt_get_value === "function" ? arg.opt_get_value({ @@ -22,6 +23,7 @@ export const TypeDropdown: FC<{ type: field.type, }) : fm.data[field.name]; + useEffect(() => { if (typeof arg.on_load === "function") { const options = arg.on_load({ field }); @@ -44,6 +46,7 @@ export const TypeDropdown: FC<{ local.options = res; } local.render(); + value = typeof arg.opt_get_value === "function" ? arg.opt_get_value({ @@ -53,9 +56,9 @@ export const TypeDropdown: FC<{ type: field.type, }) : fm.data[field.name]; + if ( field.type === "single-option" && - field.required && !value && local.options.length > 0 ) { @@ -86,6 +89,7 @@ export const TypeDropdown: FC<{ } } }, []); + let popupClassName = ""; if (arg.__props) { diff --git a/gen/gen_form/gen_form.ts b/gen/gen_form/gen_form.ts index 53e1976..030fb4a 100755 --- a/gen/gen_form/gen_form.ts +++ b/gen/gen_form/gen_form.ts @@ -4,7 +4,7 @@ import { GFCol, parseGenField } from "../utils"; import { newField } from "./new_field"; import { on_submit } from "./on_submit"; -export const gen_form = async (modify: (data: any) => void, data: any) => { +export const gen_form = async (modify: (data: any) => void, data: any, is_md?: boolean) => { const table = JSON.parse(data.gen_table.value); const raw_fields = JSON.parse(data.gen_fields.value) as ( | string @@ -43,7 +43,13 @@ export const gen_form = async (modify: (data: any) => void, data: any) => { const code = {} as any; if (data["on_load"]) { result["on_load"] = data["on_load"]; - result["on_load"].value = on_load({ pk: pk.name, pks, select, table }); + result["on_load"].value = on_load({ + pk: pk.name, + pks, + select, + table, + opt: is_md ? { is_md: true } : undefined, + }); code.on_load = result["on_load"].value; } diff --git a/gen/master_detail/gen-form.ts b/gen/master_detail/gen-form.ts index 5650c25..8022cd0 100755 --- a/gen/master_detail/gen-form.ts +++ b/gen/master_detail/gen-form.ts @@ -150,7 +150,7 @@ type Init = { submit: () => Promise; reload: () => void; fm:any } const data = childs[0].component.props; const modify = async (props: any) => {}; - await gen_form(modify, data); + await gen_form(modify, data, true); } } } diff --git a/utils/format-value.tsx b/utils/format-value.tsx index 15112be..35c0c10 100755 --- a/utils/format-value.tsx +++ b/utils/format-value.tsx @@ -44,6 +44,9 @@ export const FormatValue: FC<{ const fields = fields_map.get(gf); const field = fields?.find((e) => e.name === name); + + if (typeof value === "boolean") return <>{value ? "Yes" : "No"}; + if (mode === "money") { if (!value || isEmptyString(value)) return "-"; return formatMoney(Number(value) || 0); @@ -54,14 +57,14 @@ export const FormatValue: FC<{ } catch (ex: any) { return "-"; } - } else if (mode === "date") { + } else if (mode === "date") { if (!value || isEmptyString(value)) return "-"; try { return formatDate(dayjs(value), "DD MMMM YYYY"); } catch (ex: any) { return "-"; } - }else if (mode === "timeago") { + } else if (mode === "timeago") { if (!value || isEmptyString(value)) return "-"; try { return timeAgo(dayjs(value));