fix
This commit is contained in:
parent
c7641e154d
commit
b1f410758d
|
|
@ -36,7 +36,8 @@ export const FieldInput: FC<{
|
||||||
const errors = fm.error.get(name);
|
const errors = fm.error.get(name);
|
||||||
let type_field: any = typeof arg.type === "function" ? arg.type() : arg.type; // tipe field
|
let type_field: any = typeof arg.type === "function" ? arg.type() : arg.type; // tipe field
|
||||||
|
|
||||||
const disabled = typeof field.disabled === "function" ? field.disabled() : field.disabled;
|
const disabled =
|
||||||
|
typeof field.disabled === "function" ? field.disabled() : field.disabled;
|
||||||
let custom = <></>;
|
let custom = <></>;
|
||||||
if (field.type === "custom") {
|
if (field.type === "custom") {
|
||||||
let res = arg.custom?.() || <></>;
|
let res = arg.custom?.() || <></>;
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,11 @@ export const FieldTypeInput: FC<{
|
||||||
} else {
|
} else {
|
||||||
value = null;
|
value = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (type_field === "datetime-local" && date instanceof Date) {
|
||||||
|
date.setMinutes(date.getMinutes() - date.getTimezoneOffset());
|
||||||
|
value = date.toISOString().slice(0, 16);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
let date = parse(value);
|
let date = parse(value);
|
||||||
|
|
@ -98,6 +103,7 @@ export const FieldTypeInput: FC<{
|
||||||
|
|
||||||
const disabled =
|
const disabled =
|
||||||
typeof field.disabled === "function" ? field.disabled() : field.disabled;
|
typeof field.disabled === "function" ? field.disabled() : field.disabled;
|
||||||
|
|
||||||
switch (type_field) {
|
switch (type_field) {
|
||||||
case "toggle":
|
case "toggle":
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
|
|
@ -37,10 +37,6 @@ export const generateForm = async (
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (pk) {
|
if (pk) {
|
||||||
let is_md: boolean | string =
|
|
||||||
item.edit?.parent?.item?.component?.id ===
|
|
||||||
"cb52075a-14ab-455a-9847-6f1d929a2a73";
|
|
||||||
if (!is_md) is_md = "";
|
|
||||||
|
|
||||||
if (data["on_load"]) {
|
if (data["on_load"]) {
|
||||||
result.on_load = {
|
result.on_load = {
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,7 @@ export const generateMDForm = async (
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
generateForm(async (props: any) => {}, props, tablelist, false, true);
|
generateForm(async (props: any) => {}, props, tablelist, false, true);
|
||||||
|
|
||||||
tab_detail?.edit.setProp("breadcrumb", {
|
tab_detail?.edit.setProp("breadcrumb", {
|
||||||
mode: "raw",
|
mode: "raw",
|
||||||
value: `\
|
value: `\
|
||||||
|
|
|
||||||
|
|
@ -320,7 +320,12 @@ export const Typeahead: FC<{
|
||||||
let inputval = local.search.input;
|
let inputval = local.search.input;
|
||||||
|
|
||||||
if (!local.open && local.mode === "single" && local.value?.length > 0) {
|
if (!local.open && local.mode === "single" && local.value?.length > 0) {
|
||||||
inputval = local.value[0];
|
const found = options.find((e) => e.value === local.value[0]);
|
||||||
|
if (found) {
|
||||||
|
inputval = found.label;
|
||||||
|
} else {
|
||||||
|
inputval = local.value[0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
|
|
@ -4,73 +4,79 @@ import { GFCol, parseGenField } from "../utils";
|
||||||
import { newField } from "./new_field";
|
import { newField } from "./new_field";
|
||||||
import { on_submit } from "./on_submit";
|
import { on_submit } from "./on_submit";
|
||||||
|
|
||||||
export const gen_form = async (modify: (data: any) => void, data: any, is_md?: boolean) => {
|
export const gen_form = async (
|
||||||
const table = JSON.parse(data.gen_table.value);
|
modify: (data: any) => void,
|
||||||
const raw_fields = JSON.parse(data.gen_fields.value) as (
|
data: any,
|
||||||
| string
|
is_md?: boolean
|
||||||
| { value: string; checked: string[] }
|
) => {
|
||||||
)[];
|
console.error("FAILED TO GENERATE: OBSOLETE FUNCTION");
|
||||||
const select = {} as any;
|
// const table = JSON.parse(data.gen_table.value);
|
||||||
let pk: null | GFCol = null;
|
// const raw_fields = JSON.parse(data.gen_fields.value) as (
|
||||||
let pks: Record<string, string> = {};
|
// | string
|
||||||
|
// | { value: string; checked: string[] }
|
||||||
|
// )[];
|
||||||
|
// const select = {} as any;
|
||||||
|
// let pk: null | GFCol = null;
|
||||||
|
// let pks: Record<string, string> = {};
|
||||||
|
|
||||||
const fields = parseGenField(raw_fields);
|
// const fields = parseGenField(raw_fields);
|
||||||
const result = {} as any;
|
// const result = {} as any;
|
||||||
for (const f of fields) {
|
// for (const f of fields) {
|
||||||
select[f.name] = true;
|
// select[f.name] = true;
|
||||||
if (f.relation) {
|
// if (f.relation) {
|
||||||
select[f.name] = {
|
// select[f.name] = {
|
||||||
select: {},
|
// select: {},
|
||||||
};
|
// };
|
||||||
for (const r of f.relation.fields) {
|
// for (const r of f.relation.fields) {
|
||||||
select[f.name].select[r.name] = true;
|
// select[f.name].select[r.name] = true;
|
||||||
if (r.is_pk) {
|
// if (r.is_pk) {
|
||||||
pks[f.name] = r.name;
|
// pks[f.name] = r.name;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (f.is_pk) {
|
// if (f.is_pk) {
|
||||||
pk = f;
|
// pk = f;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (!pk) {
|
// if (!pk) {
|
||||||
alert("Failed to generate! Primary Key not found. ");
|
// alert("Failed to generate! Primary Key not found. ");
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
if (pk) {
|
|
||||||
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,
|
|
||||||
opt: is_md ? { is_md: true } : undefined,
|
|
||||||
});
|
|
||||||
code.on_load = result["on_load"].value;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data["on_submit"]) {
|
// if (pk) {
|
||||||
result["on_submit"] = data["on_submit"];
|
// const code = {} as any;
|
||||||
result["on_submit"].value = on_submit({ pk, table, select, pks });
|
// if (data["on_load"]) {
|
||||||
code.on_submit = result["on_submit"].value;
|
// result["on_load"] = data["on_load"];
|
||||||
}
|
// 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;
|
||||||
|
// }
|
||||||
|
|
||||||
const res = await codeBuild(code);
|
// if (data["on_submit"]) {
|
||||||
for (const [k, v] of Object.entries(res)) {
|
// result["on_submit"] = data["on_submit"];
|
||||||
result[k].valueBuilt = v[1];
|
// result["on_submit"].value = on_submit({ pk, table, select, pks });
|
||||||
}
|
// code.on_submit = result["on_submit"].value;
|
||||||
|
// }
|
||||||
|
|
||||||
result["body"] = data["body"];
|
// const res = await codeBuild(code);
|
||||||
result.body.content.childs = [];
|
// for (const [k, v] of Object.entries(res)) {
|
||||||
for (const item of fields.filter((e) => !e.is_pk)) {
|
// result[k].valueBuilt = v[1];
|
||||||
result.body.content.childs.push(
|
// }
|
||||||
await newField(item, { parent_table: table })
|
|
||||||
);
|
// result["body"] = data["body"];
|
||||||
}
|
// result.body.content.childs = [];
|
||||||
}
|
// for (const item of fields.filter((e) => !e.is_pk)) {
|
||||||
modify(result);
|
// result.body.content.childs.push(
|
||||||
|
// await newField(item, { parent_table: table })
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// modify(result);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue