This commit is contained in:
rizky 2024-08-08 19:56:58 -07:00
parent a425445ff2
commit 4a3374701c
5 changed files with 18 additions and 5 deletions

View File

@ -5,6 +5,7 @@ import { useField } from "../utils/use-field";
import { FieldInput } from "./FieldInput";
import { Label } from "./Label";
import { validate } from "../utils/validate";
import { call_prasi_events } from "lib/exports";
export const Field: FC<FieldProp> = (arg) => {
const showlabel = arg.show_label || "y";
@ -39,6 +40,8 @@ export const Field: FC<FieldProp> = (arg) => {
fm.events.on_change(name, fm.data[name]);
fm.render();
call_prasi_events("field", "on_change", [fm, field]);
}
}, [fm.data[name]]);

View File

@ -3,6 +3,7 @@ import { FieldLoading } from "lib/comps/ui/field-loading";
import { Typeahead } from "lib/comps/ui/typeahead";
import { FC, useEffect } from "react";
import { FMLocal, FieldLocal, FieldProp } from "../../typings";
import { call_prasi_events } from "lib/exports";
export const TypeDropdown: FC<{
field: FieldLocal;
@ -14,11 +15,12 @@ export const TypeDropdown: FC<{
options: [] as { value: string; label: string; data: any }[],
});
const reload = (callback?: () => void) => {
const reload = async (callback?: () => void) => {
if (typeof arg.on_load === "function") {
local.loaded = false;
local.render();
const options = arg.on_load({ field });
let options: any = null;
options = arg.on_load({ field });
if (options instanceof Promise) {
options.then((res) => {
if (Array.isArray(res)) {

View File

@ -54,6 +54,15 @@ export const newField = async (
},
});
} else {
let sub_type = "text";
if (
["attachment", "file", "img", "image"].find((e) =>
field.name.includes(e)
)
) {
sub_type = "file";
}
return createItem({
component: {
id: "32550d01-42a3-4b15-a04a-2c2d5c3c8e67",
@ -62,7 +71,7 @@ export const newField = async (
label: formatName(field.name),
type,
ext__required: field.optional ? "n" : "y",
sub_type: "text",
sub_type,
ext__show_label: show ? "y" : "n",
child: {
childs: [],

View File

@ -90,6 +90,7 @@ ${
return item;
} else {
call_prasi_events("form", "after_load", [opt?.fm]);
${opt?.after_load ? opt?.after_load : ""}
}
}`;

View File

@ -20,9 +20,7 @@ const events = {
},
},
field: {
on_init: async (fm: FMLocal, field: FieldLocal) => {},
on_change: async (fm: FMLocal, field: FieldLocal) => {},
options_load: async (fm: FMLocal, field: FieldLocal) => {},
},
tablelist: {
after_load: async <T extends Prisma.ModelName>(