This commit is contained in:
Rizky 2024-07-05 22:32:29 -07:00
parent d4a8c9932b
commit ee154438c1
5 changed files with 23 additions and 7 deletions

View File

@ -160,7 +160,10 @@ export const Form: FC<FMProps> = (props) => {
if (!ref.current.el) {
ref.current.el = el;
ref.current.rob.observe(el);
if (fm.status === "ready") {
fm.status = "resizing";
fm.render();
}
}
}
}}

View File

@ -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) {

View File

@ -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;
}

View File

@ -150,7 +150,7 @@ type Init = { submit: () => Promise<boolean>; 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);
}
}
}

View File

@ -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);
@ -61,7 +64,7 @@ export const FormatValue: FC<{
} catch (ex: any) {
return "-";
}
}else if (mode === "timeago") {
} else if (mode === "timeago") {
if (!value || isEmptyString(value)) return "-";
try {
return timeAgo(dayjs(value));