fix form
This commit is contained in:
parent
eb3c803d4d
commit
32ead5308f
|
|
@ -1,7 +1,7 @@
|
||||||
import { ReactNode, useCallback, useEffect, useState } from "react";
|
import { ReactNode, useCallback, useEffect, useState } from "react";
|
||||||
import { BaseFormLocal, default_base_form_local } from "./types";
|
import { BaseFormLocal, default_base_form_local } from "./types";
|
||||||
import { useLocal } from "lib/utils/use-local";
|
import { useLocal } from "lib/utils/use-local";
|
||||||
import { FieldLocal, FieldProp } from "../typings";
|
import { FieldLocal, FieldProp, fieldType } from "../typings";
|
||||||
|
|
||||||
export type BaseFormProps<T> = {
|
export type BaseFormProps<T> = {
|
||||||
data: T;
|
data: T;
|
||||||
|
|
@ -47,6 +47,8 @@ export const BaseForm = <T extends Record<string, any>>(
|
||||||
};
|
};
|
||||||
|
|
||||||
form.createField = (arg) => {
|
form.createField = (arg) => {
|
||||||
|
if (form.fields[arg.name]) return form.fields[arg.name];
|
||||||
|
|
||||||
const prop: FieldLocal = {
|
const prop: FieldLocal = {
|
||||||
name: arg.name,
|
name: arg.name,
|
||||||
label: typeof arg.label !== "undefined" ? arg.label : arg.name,
|
label: typeof arg.label !== "undefined" ? arg.label : arg.name,
|
||||||
|
|
@ -54,6 +56,7 @@ export const BaseForm = <T extends Record<string, any>>(
|
||||||
width: "auto",
|
width: "auto",
|
||||||
prefix: arg.prefix,
|
prefix: arg.prefix,
|
||||||
} as any;
|
} as any;
|
||||||
|
form.fields[arg.name] = prop;
|
||||||
return prop;
|
return prop;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ export const default_base_form_local = {
|
||||||
width: 0,
|
width: 0,
|
||||||
},
|
},
|
||||||
fm: null as null | FMLocal,
|
fm: null as null | FMLocal,
|
||||||
|
fields: {} as Record<string, any>,
|
||||||
};
|
};
|
||||||
|
|
||||||
type CreateFieldArg = {
|
type CreateFieldArg = {
|
||||||
|
|
|
||||||
|
|
@ -200,7 +200,6 @@ export const FieldTypeInput: FC<{
|
||||||
field.render();
|
field.render();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{arg.sub_type === "password" && (
|
{arg.sub_type === "password" && (
|
||||||
<div
|
<div
|
||||||
className="c-absolute c-right-0 c-h-full c-flex c-items-center c-cursor-pointer"
|
className="c-absolute c-right-0 c-h-full c-flex c-items-center c-cursor-pointer"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue