fix form
This commit is contained in:
parent
03563068ef
commit
15a37a2b27
|
|
@ -58,7 +58,10 @@ export const Form: FC<FMProps> = (props) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (props.render_parent) {
|
if (props.render_parent) {
|
||||||
fm.render = props.render_parent;
|
if (!fm.internal.original_render) fm.internal.original_render = fm.render;
|
||||||
|
fm.render = () => {
|
||||||
|
if (props.render_parent) props.render_parent();
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -141,11 +144,7 @@ export const Form: FC<FMProps> = (props) => {
|
||||||
const toaster_el = document.getElementsByClassName("prasi-toaster")[0];
|
const toaster_el = document.getElementsByClassName("prasi-toaster")[0];
|
||||||
|
|
||||||
if (fm.status === "resizing") {
|
if (fm.status === "resizing") {
|
||||||
setTimeout(() => {
|
fm.status = "ready";
|
||||||
fm.status = "ready";
|
|
||||||
fm.render();
|
|
||||||
}, 100);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
@ -153,7 +152,7 @@ export const Form: FC<FMProps> = (props) => {
|
||||||
onSubmit={(e) => {
|
onSubmit={(e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
console.log("HALOO")
|
console.log("HALOO");
|
||||||
fm.submit();
|
fm.submit();
|
||||||
}}
|
}}
|
||||||
ref={(el) => {
|
ref={(el) => {
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,16 @@ export const TypeDropdown: FC<{
|
||||||
} else {
|
} else {
|
||||||
local.options = res;
|
local.options = res;
|
||||||
}
|
}
|
||||||
|
local.render();
|
||||||
|
value =
|
||||||
|
typeof arg.opt_get_value === "function"
|
||||||
|
? arg.opt_get_value({
|
||||||
|
fm,
|
||||||
|
name: field.name,
|
||||||
|
options: local.options,
|
||||||
|
type: field.type,
|
||||||
|
})
|
||||||
|
: fm.data[field.name];
|
||||||
if (
|
if (
|
||||||
field.type === "single-option" &&
|
field.type === "single-option" &&
|
||||||
field.required &&
|
field.required &&
|
||||||
|
|
|
||||||
|
|
@ -173,11 +173,14 @@ export const FieldTypeInput: FC<{
|
||||||
case "rich-text":
|
case "rich-text":
|
||||||
return <FieldRichText field={field} fm={fm} prop={prop} />;
|
return <FieldRichText field={field} fm={fm} prop={prop} />;
|
||||||
case "date":
|
case "date":
|
||||||
|
console.log(field.min_date instanceof Date)
|
||||||
return (
|
return (
|
||||||
<Datepicker
|
<Datepicker
|
||||||
value={{ startDate: value, endDate: value }}
|
value={{ startDate: value, endDate: value }}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
displayFormat="DD MMM YYYY"
|
displayFormat="DD MMM YYYY"
|
||||||
|
maxDate={field.max_date instanceof Date ? field.max_date : null}
|
||||||
|
minDate={field.min_date instanceof Date? field.min_date : null}
|
||||||
asSingle={true}
|
asSingle={true}
|
||||||
useRange={false}
|
useRange={false}
|
||||||
onChange={(value) => {
|
onChange={(value) => {
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ export type FieldProp = {
|
||||||
required_msg: (name: string) => string | ReactElement;
|
required_msg: (name: string) => string | ReactElement;
|
||||||
on_change: (arg: { value: any }) => void | Promise<void>;
|
on_change: (arg: { value: any }) => void | Promise<void>;
|
||||||
PassProp: any;
|
PassProp: any;
|
||||||
disabled: ("y" | "n") | (() => true | false);
|
disabled: ("y" | "n") | (() => true | false);
|
||||||
child: any;
|
child: any;
|
||||||
selection: "single" | "multi";
|
selection: "single" | "multi";
|
||||||
prefix: any;
|
prefix: any;
|
||||||
|
|
@ -99,6 +99,8 @@ export type FieldProp = {
|
||||||
gen_table?: string;
|
gen_table?: string;
|
||||||
gen_fields?: string;
|
gen_fields?: string;
|
||||||
model_upload?: "upload" | "import";
|
model_upload?: "upload" | "import";
|
||||||
|
max_date?: any;
|
||||||
|
min_date?: any;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type FMInternal = {
|
export type FMInternal = {
|
||||||
|
|
@ -129,6 +131,7 @@ export type FMInternal = {
|
||||||
timeout: ReturnType<typeof setTimeout>;
|
timeout: ReturnType<typeof setTimeout>;
|
||||||
done: any[];
|
done: any[];
|
||||||
};
|
};
|
||||||
|
original_render?: () => void;
|
||||||
};
|
};
|
||||||
props: Exclude<FMProps, "body" | "PassProp">;
|
props: Exclude<FMProps, "body" | "PassProp">;
|
||||||
size: {
|
size: {
|
||||||
|
|
@ -171,6 +174,8 @@ export type FieldInternal<T extends FieldProp["type"]> = {
|
||||||
fm: FMLocal;
|
fm: FMLocal;
|
||||||
}) => void | Promise<void>;
|
}) => void | Promise<void>;
|
||||||
prop?: any;
|
prop?: any;
|
||||||
|
max_date?: FieldProp["max_date"];
|
||||||
|
min_date?: FieldProp["min_date"];
|
||||||
};
|
};
|
||||||
export type FieldLocal = FieldInternal<any> & {
|
export type FieldLocal = FieldInternal<any> & {
|
||||||
render: () => void;
|
render: () => void;
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,8 @@ export const useField = (
|
||||||
required_msg: arg.required_msg,
|
required_msg: arg.required_msg,
|
||||||
disabled: typeof arg.disabled === "function" ? arg.disabled : arg.disabled === "y",
|
disabled: typeof arg.disabled === "function" ? arg.disabled : arg.disabled === "y",
|
||||||
on_change: arg.on_change,
|
on_change: arg.on_change,
|
||||||
|
max_date: arg.max_date,
|
||||||
|
min_date: arg.min_date,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (field.status === "init" || isEditor) {
|
if (field.status === "init" || isEditor) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue