This commit is contained in:
Rizky 2024-07-05 00:02:40 -07:00
parent 03563068ef
commit 15a37a2b27
5 changed files with 27 additions and 8 deletions

View File

@ -58,7 +58,10 @@ export const Form: FC<FMProps> = (props) => {
});
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(() => {
@ -141,11 +144,7 @@ export const Form: FC<FMProps> = (props) => {
const toaster_el = document.getElementsByClassName("prasi-toaster")[0];
if (fm.status === "resizing") {
setTimeout(() => {
fm.status = "ready";
fm.render();
}, 100);
return null;
fm.status = "ready";
}
return (
@ -153,7 +152,7 @@ export const Form: FC<FMProps> = (props) => {
onSubmit={(e) => {
e.preventDefault();
e.stopPropagation();
console.log("HALOO")
console.log("HALOO");
fm.submit();
}}
ref={(el) => {

View File

@ -43,6 +43,16 @@ export const TypeDropdown: FC<{
} else {
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 (
field.type === "single-option" &&
field.required &&

View File

@ -173,11 +173,14 @@ export const FieldTypeInput: FC<{
case "rich-text":
return <FieldRichText field={field} fm={fm} prop={prop} />;
case "date":
console.log(field.min_date instanceof Date)
return (
<Datepicker
value={{ startDate: value, endDate: value }}
disabled={disabled}
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}
useRange={false}
onChange={(value) => {

View File

@ -53,7 +53,7 @@ export type FieldProp = {
required_msg: (name: string) => string | ReactElement;
on_change: (arg: { value: any }) => void | Promise<void>;
PassProp: any;
disabled: ("y" | "n") | (() => true | false);
disabled: ("y" | "n") | (() => true | false);
child: any;
selection: "single" | "multi";
prefix: any;
@ -99,6 +99,8 @@ export type FieldProp = {
gen_table?: string;
gen_fields?: string;
model_upload?: "upload" | "import";
max_date?: any;
min_date?: any;
};
export type FMInternal = {
@ -129,6 +131,7 @@ export type FMInternal = {
timeout: ReturnType<typeof setTimeout>;
done: any[];
};
original_render?: () => void;
};
props: Exclude<FMProps, "body" | "PassProp">;
size: {
@ -171,6 +174,8 @@ export type FieldInternal<T extends FieldProp["type"]> = {
fm: FMLocal;
}) => void | Promise<void>;
prop?: any;
max_date?: FieldProp["max_date"];
min_date?: FieldProp["min_date"];
};
export type FieldLocal = FieldInternal<any> & {
render: () => void;

View File

@ -36,6 +36,8 @@ export const useField = (
required_msg: arg.required_msg,
disabled: typeof arg.disabled === "function" ? arg.disabled : arg.disabled === "y",
on_change: arg.on_change,
max_date: arg.max_date,
min_date: arg.min_date,
};
if (field.status === "init" || isEditor) {