diff --git a/comps/form/field/Field.tsx b/comps/form/field/Field.tsx index 0a4ec44..073ca2a 100755 --- a/comps/form/field/Field.tsx +++ b/comps/form/field/Field.tsx @@ -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 = (arg) => { const showlabel = arg.show_label || "y"; @@ -39,6 +40,8 @@ export const Field: FC = (arg) => { fm.events.on_change(name, fm.data[name]); fm.render(); + + call_prasi_events("field", "on_change", [fm, field]); } }, [fm.data[name]]); diff --git a/comps/form/field/type/TypeDropdown.tsx b/comps/form/field/type/TypeDropdown.tsx index bb927e3..2d4dbc6 100755 --- a/comps/form/field/type/TypeDropdown.tsx +++ b/comps/form/field/type/TypeDropdown.tsx @@ -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)) { diff --git a/comps/form/gen/fields.ts b/comps/form/gen/fields.ts index 6898e5f..c6f5374 100755 --- a/comps/form/gen/fields.ts +++ b/comps/form/gen/fields.ts @@ -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: [], diff --git a/comps/form/gen/on_load.ts b/comps/form/gen/on_load.ts index bd87d87..8c64a57 100755 --- a/comps/form/gen/on_load.ts +++ b/comps/form/gen/on_load.ts @@ -90,6 +90,7 @@ ${ return item; } else { + call_prasi_events("form", "after_load", [opt?.fm]); ${opt?.after_load ? opt?.after_load : ""} } }`; diff --git a/utils/prasi-events.ts b/utils/prasi-events.ts index 0c1974d..9382800 100755 --- a/utils/prasi-events.ts +++ b/utils/prasi-events.ts @@ -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 (