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