fix
This commit is contained in:
parent
ae8ab53182
commit
dc22fc5a45
|
|
@ -14,7 +14,7 @@ export const TypeDropdown: FC<{
|
|||
options: [] as { value: string; label: string; data: any }[],
|
||||
});
|
||||
|
||||
const reload = () => {
|
||||
const reload = (callback?: () => void) => {
|
||||
if (typeof arg.on_load === "function") {
|
||||
local.loaded = false;
|
||||
local.render();
|
||||
|
|
@ -71,14 +71,21 @@ export const TypeDropdown: FC<{
|
|||
|
||||
local.loaded = true;
|
||||
local.render();
|
||||
callback?.();
|
||||
});
|
||||
} else {
|
||||
local.loaded = true;
|
||||
local.options = Array.isArray(options) ? options : ([] as any);
|
||||
local.render();
|
||||
callback?.();
|
||||
}
|
||||
}
|
||||
};
|
||||
field.reload_options = () => {
|
||||
return new Promise((done) => {
|
||||
reload(done);
|
||||
});
|
||||
};
|
||||
|
||||
if ((arg.load_trigger?.deps || []).length > 0 && !isEditor) {
|
||||
useEffect(
|
||||
|
|
|
|||
|
|
@ -196,6 +196,7 @@ export type FieldInternal<T extends FieldProp["type"]> = {
|
|||
options: {
|
||||
on_load?: () => Promise<{ value: string; label: string }[]>;
|
||||
};
|
||||
reload_options: () => Promise<void>;
|
||||
on_change?: (arg: {
|
||||
value: any;
|
||||
name: string;
|
||||
|
|
|
|||
|
|
@ -16,14 +16,15 @@ export const useField = (
|
|||
input: {},
|
||||
ref: null as any,
|
||||
} as any);
|
||||
const ref = useRef(null as any)
|
||||
const ref = useRef(null as any);
|
||||
field.ref = ref;
|
||||
|
||||
const name = typeof arg.name === "string" ? arg.name : arg.name();
|
||||
const label = typeof arg.label === "string" ? arg.label : arg.label();
|
||||
const required =
|
||||
typeof arg.required === "string" ? arg.required : arg.required();
|
||||
const update_field = {
|
||||
|
||||
if (field.status === "init" || isEditor) {
|
||||
for (const [k, v] of Object.entries({
|
||||
name: name.replace(/\s*/gi, ""),
|
||||
label: label,
|
||||
type: arg.type,
|
||||
|
|
@ -34,14 +35,16 @@ export const useField = (
|
|||
custom: arg.custom,
|
||||
required: required === "y",
|
||||
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,
|
||||
max_date: arg.max_date,
|
||||
min_date: arg.min_date,
|
||||
};
|
||||
|
||||
if (field.status === "init" || isEditor) {
|
||||
for (const [k, v] of Object.entries(update_field)) {
|
||||
options: {},
|
||||
reload_options: () => {},
|
||||
})) {
|
||||
(field as any)[k] = v;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { FieldLocal } from "lib/comps/form/typings";
|
||||
import { FMLocal } from "../..";
|
||||
import { set } from "./set";
|
||||
import { MDLocal } from "lib/comps/md/utils/typings";
|
||||
import { FMLocal } from "../..";
|
||||
import { Prisma } from "../../typings/prisma";
|
||||
import { set } from "./set";
|
||||
|
||||
const events = {
|
||||
form: {
|
||||
|
|
@ -20,9 +20,9 @@ const events = {
|
|||
},
|
||||
},
|
||||
field: {
|
||||
relation_load: async (fm: FMLocal, field: FieldLocal) => {
|
||||
return {} as Record<string, any>;
|
||||
},
|
||||
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>(
|
||||
|
|
@ -34,6 +34,11 @@ const events = {
|
|||
},
|
||||
};
|
||||
|
||||
type TriggerOnChange = {
|
||||
fm: FMLocal;
|
||||
md: any;
|
||||
where: any;
|
||||
};
|
||||
type PRASI_EVENT = typeof events;
|
||||
export const prasi_events = <
|
||||
K extends keyof PRASI_EVENT,
|
||||
|
|
|
|||
Loading…
Reference in New Issue