fix base-form
This commit is contained in:
parent
8771409229
commit
cb28c0fe82
|
|
@ -94,7 +94,6 @@ export const BaseForm = <T extends Record<string, any>>({
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{toaster_el && createPortal(<Toaster />, toaster_el)}
|
{toaster_el && createPortal(<Toaster />, toaster_el)}
|
||||||
|
|
||||||
<div
|
<div
|
||||||
className={cx(
|
className={cx(
|
||||||
"form-inner c-flex-1 c-flex c-flex-row c-flex-wrap c-items-start c-content-start c-absolute c-inset-0",
|
"form-inner c-flex-1 c-flex c-flex-row c-flex-wrap c-items-start c-content-start c-absolute c-inset-0",
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,11 @@ export const DivForm = forwardRef<
|
||||||
HTMLFormElement
|
HTMLFormElement
|
||||||
> & { tag: "form" | "div" }
|
> & { tag: "form" | "div" }
|
||||||
>((arg, ref) => {
|
>((arg, ref) => {
|
||||||
if (arg.tag === "div") {
|
|
||||||
const props = { ...arg } as any;
|
const props = { ...arg } as any;
|
||||||
|
delete props.tag;
|
||||||
|
if (arg.tag === "div") {
|
||||||
if (props.onSubmit) delete props.onSubmit;
|
if (props.onSubmit) delete props.onSubmit;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div {...props} ref={ref}>
|
<div {...props} ref={ref}>
|
||||||
{arg.children}
|
{arg.children}
|
||||||
|
|
@ -17,7 +19,7 @@ export const DivForm = forwardRef<
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<form {...arg} ref={ref}>
|
<form {...props} ref={ref}>
|
||||||
{arg?.children}
|
{arg?.children}
|
||||||
</form>
|
</form>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ export const Field: FC<FieldProp> = (arg) => {
|
||||||
arg.on_change({ value: fm.data?.[name], name, fm });
|
arg.on_change({ value: fm.data?.[name], name, fm });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fm.deps.md) {
|
if (fm.deps?.md) {
|
||||||
fm.save_status = "unsaved";
|
fm.save_status = "unsaved";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -134,8 +134,8 @@ export const Field: FC<FieldProp> = (arg) => {
|
||||||
: css`
|
: css`
|
||||||
padding: 5px 0px 0px 10px;
|
padding: 5px 0px 0px 10px;
|
||||||
`,
|
`,
|
||||||
w === "auto" && fm.size.field === "full" && "c-w-full",
|
w === "auto" && fm.size?.field === "full" && "c-w-full",
|
||||||
w === "auto" && fm.size.field === "half" && "c-w-1/2",
|
w === "auto" && fm.size?.field === "half" && "c-w-1/2",
|
||||||
w === "full" && "c-w-full",
|
w === "full" && "c-w-full",
|
||||||
w === "¾" && "c-w-3/4",
|
w === "¾" && "c-w-3/4",
|
||||||
w === "½" && "c-w-1/2",
|
w === "½" && "c-w-1/2",
|
||||||
|
|
@ -175,7 +175,7 @@ export const Field: FC<FieldProp> = (arg) => {
|
||||||
fm={fm}
|
fm={fm}
|
||||||
PassProp={arg.PassProp}
|
PassProp={arg.PassProp}
|
||||||
child={arg.child}
|
child={arg.child}
|
||||||
_item={arg._item}
|
_item={arg._item!}
|
||||||
arg={arg}
|
arg={arg}
|
||||||
/>
|
/>
|
||||||
{field.desc && (
|
{field.desc && (
|
||||||
|
|
|
||||||
|
|
@ -197,10 +197,15 @@ export const TableEdit: FC<{
|
||||||
.typeahead-arrow {
|
.typeahead-arrow {
|
||||||
margin-right: 10px;
|
margin-right: 10px;
|
||||||
}
|
}
|
||||||
|
tbody > .form {
|
||||||
|
overflow: visible;
|
||||||
|
& > .form-inner {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
}
|
||||||
`
|
`
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{/* {JSON.stringify(value.map((e) => e.id))} */}
|
|
||||||
<table
|
<table
|
||||||
className={cx(
|
className={cx(
|
||||||
"c-table-auto",
|
"c-table-auto",
|
||||||
|
|
@ -266,12 +271,17 @@ export const TableEdit: FC<{
|
||||||
<>
|
<>
|
||||||
{value.map((row: any, idx: number) => {
|
{value.map((row: any, idx: number) => {
|
||||||
return (
|
return (
|
||||||
<BaseForm name="table-edit-form" tag={"div"} data={row}>
|
<BaseForm
|
||||||
|
key={idx}
|
||||||
|
name={`tef-${idx}`}
|
||||||
|
tag={"div"}
|
||||||
|
data={row}
|
||||||
|
>
|
||||||
{(form) => {
|
{(form) => {
|
||||||
return (
|
return (
|
||||||
<tr
|
<tr
|
||||||
className={cx(
|
className={cx(
|
||||||
"c-border-b ",
|
"c-border-b c-py-1",
|
||||||
idx !== value.length - 1
|
idx !== value.length - 1
|
||||||
? "c-border-gray-300"
|
? "c-border-gray-300"
|
||||||
: ""
|
: ""
|
||||||
|
|
@ -281,18 +291,15 @@ export const TableEdit: FC<{
|
||||||
return (
|
return (
|
||||||
<td
|
<td
|
||||||
className={cx(
|
className={cx(
|
||||||
|
css`
|
||||||
|
vertical-align: top;
|
||||||
|
`,
|
||||||
header.width || 0 > 0
|
header.width || 0 > 0
|
||||||
? css`
|
? css`
|
||||||
width: ${header.width || 0}px;
|
width: ${header.width || 0}px;
|
||||||
`
|
`
|
||||||
: ""
|
: ""
|
||||||
)}
|
)}
|
||||||
>
|
|
||||||
<div
|
|
||||||
className={cx(
|
|
||||||
"c-flex c-flex-row c-pb-1 c-w-full c-h-full",
|
|
||||||
idx === 0 && "c-pt-1"
|
|
||||||
)}
|
|
||||||
>
|
>
|
||||||
{header.renderCell({
|
{header.renderCell({
|
||||||
props: {
|
props: {
|
||||||
|
|
@ -308,7 +315,6 @@ export const TableEdit: FC<{
|
||||||
data: value,
|
data: value,
|
||||||
},
|
},
|
||||||
})}
|
})}
|
||||||
</div>
|
|
||||||
</td>
|
</td>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|
@ -333,7 +339,6 @@ export const TableEdit: FC<{
|
||||||
} else {
|
} else {
|
||||||
fm.data[name] = [{ ...e }];
|
fm.data[name] = [{ ...e }];
|
||||||
}
|
}
|
||||||
console.log("CEKK");
|
|
||||||
fm.render();
|
fm.render();
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const last = Array.from(
|
const last = Array.from(
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,7 @@ export type FieldProp = {
|
||||||
export type FMInternal = {
|
export type FMInternal = {
|
||||||
status: "init" | "resizing" | "loading" | "saving" | "ready";
|
status: "init" | "resizing" | "loading" | "saving" | "ready";
|
||||||
data: any;
|
data: any;
|
||||||
deps: any;
|
deps?: any;
|
||||||
reload: () => Promise<void>;
|
reload: () => Promise<void>;
|
||||||
submit: () => Promise<boolean>;
|
submit: () => Promise<boolean>;
|
||||||
events: {
|
events: {
|
||||||
|
|
|
||||||
|
|
@ -14,10 +14,10 @@ export const formInit = (fm: FMLocal, props: FMProps) => {
|
||||||
if (["PassProp", "body", "meta", "item"].includes(k)) continue;
|
if (["PassProp", "body", "meta", "item"].includes(k)) continue;
|
||||||
(fm.props as any)[k] = v;
|
(fm.props as any)[k] = v;
|
||||||
}
|
}
|
||||||
const { on_load, sonar } = fm.props;
|
const { on_load, sonar } = (fm.props || {});
|
||||||
fm.error = formError(fm);
|
fm.error = formError(fm);
|
||||||
fm.field_def = {};
|
fm.field_def = {};
|
||||||
const defs = parseGenField(fm.props.gen_fields);
|
const defs = parseGenField(fm.props?.gen_fields);
|
||||||
for (const d of defs) {
|
for (const d of defs) {
|
||||||
fm.field_def[d.name] = d;
|
fm.field_def[d.name] = d;
|
||||||
}
|
}
|
||||||
|
|
@ -223,11 +223,11 @@ export const formInit = (fm: FMLocal, props: FMProps) => {
|
||||||
if (fm.status !== "ready") {
|
if (fm.status !== "ready") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (typeof fm.props.on_submit === "function") {
|
if (typeof fm.props?.on_submit === "function") {
|
||||||
fm.status = "saving";
|
fm.status = "saving";
|
||||||
fm.render();
|
fm.render();
|
||||||
|
|
||||||
if (fm.props.sonar === "on" && !isEditor) {
|
if (fm.props?.sonar === "on" && !isEditor) {
|
||||||
toast.loading(
|
toast.loading(
|
||||||
<>
|
<>
|
||||||
<Loader2 className="c-h-4 c-w-4 c-animate-spin" />
|
<Loader2 className="c-h-4 c-w-4 c-animate-spin" />
|
||||||
|
|
@ -237,7 +237,7 @@ export const formInit = (fm: FMLocal, props: FMProps) => {
|
||||||
}
|
}
|
||||||
const form = JSON.parse(JSON.stringify(fm.data));
|
const form = JSON.parse(JSON.stringify(fm.data));
|
||||||
|
|
||||||
if (fm.deps.md) {
|
if (fm.deps?.md) {
|
||||||
const md = fm.deps.md;
|
const md = fm.deps.md;
|
||||||
const last = md.params.links[md.params.links.length - 1];
|
const last = md.params.links[md.params.links.length - 1];
|
||||||
if (last) {
|
if (last) {
|
||||||
|
|
@ -298,7 +298,7 @@ export const formInit = (fm: FMLocal, props: FMProps) => {
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (typeof fm.props.on_init === "function") {
|
if (typeof fm.props?.on_init === "function") {
|
||||||
fm.props.on_init({ fm, submit: fm.submit, reload: fm.reload });
|
fm.props.on_init({ fm, submit: fm.submit, reload: fm.reload });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue