diff --git a/comps/form/field/table-edit/TableEdit.tsx b/comps/form/field/table-edit/TableEdit.tsx index d13672f..1f3b4ef 100755 --- a/comps/form/field/table-edit/TableEdit.tsx +++ b/comps/form/field/table-edit/TableEdit.tsx @@ -62,6 +62,9 @@ export const TableEdit: FC<{ .table-list-inner { position: relative !important; } + .typeahead-arrow { + margin-right: 10px; + } `, value.length === 0 && (show_header === "n" @@ -83,12 +86,16 @@ export const TableEdit: FC<{ { const rh = local.rowHeight.get(row); + + let h = 50; if (rh) { for (const div of Object.values(rh)) { - if (div.offsetHeight > 50) return div.offsetHeight + 6; + if (div) { + if (div.offsetHeight > 50) h = div.offsetHeight + 6; + } } } - return 50; + return h; }} feature={[]} child={child} @@ -118,6 +125,14 @@ export const TableEdit: FC<{ local.tbl = tbl; const key = props.column.key; + + if (!local.rowHeight.has(props.row)) { + local.rowHeight.set(props.row, {}); + } + const rh = local.rowHeight.get(props.row); + if (rh && tbl.el) { + rh[props.column.key] = tbl.el.querySelector(".field"); + } return ( { - if (ref) { - if (!local.rowHeight.has(props.row)) { - local.rowHeight.set(props.row, {}); - } - const rh = local.rowHeight.get(props.row); - if (rh) { - rh[props.column.key] = ref; - } - } - }} fm_parent={parent} ext_fm={{ idx: props.rowIdx, diff --git a/comps/form/gen/fields.ts b/comps/form/gen/fields.ts index aa5f4fc..9b5f945 100755 --- a/comps/form/gen/fields.ts +++ b/comps/form/gen/fields.ts @@ -308,7 +308,7 @@ return (React.createElement(React.Fragment, null, let sub_type = "typeahead"; if (field.relation?.fields.filter((e) => !e.is_pk)?.length >= 2) { - sub_type = "table-edit"; + sub_type = "table-edit"; child = createItem({ childs: await generateRelation( { @@ -320,7 +320,7 @@ return (React.createElement(React.Fragment, null, false ), }); - } else { + } else if (!opt.is_from_table_edit) { type = "link"; } diff --git a/comps/form/gen/gen-rel-many.ts b/comps/form/gen/gen-rel-many.ts index 440302a..926a830 100755 --- a/comps/form/gen/gen-rel-many.ts +++ b/comps/form/gen/gen-rel-many.ts @@ -58,11 +58,11 @@ export const genRelMany = (prop: { data.map((e) => { try { if (typeof e === "object") { - if (typeof e["${master.name}"].connect?.${pk_master.name} === "string") { + if (typeof e["${master.name}"]?.connect?.${pk_master.name} !== "undefined") { selected.push(e["${master.name}"].connect.${pk_master.name}); - } else if (typeof e["${master.name}"]?.${pk_master.name} === "string") { + } else if (typeof e["${master.name}"]?.${pk_master.name}!== "undefined") { selected.push(e["${master.name}"].${pk_master.name}); - } + } } } catch (ex) { } }) @@ -92,15 +92,18 @@ export const genRelMany = (prop: { break; case "multi-option": let parent = {} as any; - try { + call_prasi_events("form", "relation_before_save", ["${arg.relation.to.table}", parent]); + + if (fm.data.id){ parent = { + ...parent, ${arg.relation.from.table}: { connect: { ${arg.relation.from.fields[0]}: fm.data.id || null, }, }, }; - } catch (e) {} + } fm.data[name] = selected.map((e) => { return { ${master.name}: { diff --git a/comps/form/gen/gen-table-edit.ts b/comps/form/gen/gen-table-edit.ts index b12203a..aa3aaa1 100755 --- a/comps/form/gen/gen-table-edit.ts +++ b/comps/form/gen/gen-table-edit.ts @@ -46,7 +46,7 @@ export const genTableEdit = async ( parent_table: table, value, on_change: `() => { ext_fm.change(); }`, - is_from_table_edit: true + is_from_table_edit: true, }, false ); @@ -78,6 +78,7 @@ export const genTableEdit = async ( props: { name: "option", title: "", + width: "`75`", child: { id: createId(), name: "option", @@ -88,6 +89,7 @@ export const genTableEdit = async ( adv: { css: "" }, dim: { h: "fit", w: "fit" }, name: "info", + hidden: "all", type: "item", childs: [ { diff --git a/comps/form/gen/on_load_rel.ts b/comps/form/gen/on_load_rel.ts index ab882d4..e4306c2 100755 --- a/comps/form/gen/on_load_rel.ts +++ b/comps/form/gen/on_load_rel.ts @@ -73,7 +73,7 @@ async (arg: { items = sortTree(items, rel__id_parent, "${pk}"); } - if(items.length){ + if(Array.isArray(items) && items.length){ const cols = ${JSON.stringify(cols)}; const getLabel = (data: any) => { const result = []; diff --git a/comps/md/gen/md-select.ts b/comps/md/gen/md-select.ts index 69f8660..7b2e5c0 100755 --- a/comps/md/gen/md-select.ts +++ b/comps/md/gen/md-select.ts @@ -15,6 +15,14 @@ export const generateSelect = (data: Array) => { } } else { select[f.name].select[r.name] = true; + + if (r.relation) { + if (r.relation?.fields) { + select[f.name].select[r.name] = { + select: generateSelect(r.relation?.fields).select, + }; + } + } } } } diff --git a/comps/ui/typeahead.tsx b/comps/ui/typeahead.tsx index 600cfb5..d51aea8 100755 --- a/comps/ui/typeahead.tsx +++ b/comps/ui/typeahead.tsx @@ -316,7 +316,7 @@ export const Typeahead: FC<{ return item; } - const item = local.options.find((item) => item.value === value); + const item = local.options.find((e) => e.value === value); return item; }); @@ -378,7 +378,6 @@ export const Typeahead: FC<{ ) : ( <> )} - { @@ -534,11 +533,10 @@ export const Typeahead: FC<{ onKeyDown={keydown} /> - {local.mode === "single" && (
{ @@ -145,6 +146,7 @@ export const createItem = (arg: SimplifiedItem): any => { type: "item", component, adv: arg.adv, + hidden: arg.hidden, childs: arg.childs?.map(createItem) || [], }; };