submit 'type' fixes
This commit is contained in:
parent
e2767a922c
commit
e966f8551d
1 changed files with 8 additions and 9 deletions
|
|
@ -107,20 +107,22 @@ function useOptions(path: string) {
|
|||
});
|
||||
};
|
||||
}
|
||||
|
||||
} else if (rawPath === "repeater-choices") {
|
||||
// target=<collection>, group=<repeater field>, field=<child field>
|
||||
const group = params.get("group") || "";
|
||||
const field = params.get("field") || "";
|
||||
|
||||
const fieldsUrl = `${API}/fields/${encodeURIComponent(target)}`;
|
||||
// 1) use filter endpoint form
|
||||
const fieldsUrl = `${API}/fields?filter[collection][_eq]=${encodeURIComponent(target)}`;
|
||||
const metaRes = await fetch(fieldsUrl, { cache: "no-store", credentials: "include" });
|
||||
if (!metaRes.ok) throw new Error(`Directus ${metaRes.status} fetching ${fieldsUrl}`);
|
||||
const metaJson = await metaRes.json();
|
||||
const rows = metaJson?.data ?? [];
|
||||
|
||||
// Approach 1: check nested children under the repeater parent
|
||||
// 2) read children from options.fields (not meta)
|
||||
const parent = rows.find((r: any) => r?.field === group);
|
||||
const children = parent?.meta?.options?.fields || [];
|
||||
const children = (parent?.options?.fields as any[]) || [];
|
||||
let child = children.find((f: any) => f?.field === field);
|
||||
|
||||
// Approach 2: fallback to flat "group.field" entry if present
|
||||
|
|
@ -129,11 +131,8 @@ function useOptions(path: string) {
|
|||
child = rows.find((r: any) => r?.field === full);
|
||||
}
|
||||
|
||||
// ⟵ PATCH: read choices from nested child.options.choices first, then meta.options.choices
|
||||
const choices: any[] =
|
||||
(child?.options?.choices as any[]) ||
|
||||
(child?.meta?.options?.choices as any[]) ||
|
||||
[];
|
||||
// 3) choices from options.choices only
|
||||
const choices: any[] = (child?.options?.choices as any[]) || [];
|
||||
|
||||
const mapped: Opt[] = choices.map((c: any) => ({
|
||||
id: String(c.value ?? c.key ?? c.id),
|
||||
|
|
@ -148,7 +147,7 @@ function useOptions(path: string) {
|
|||
}
|
||||
return; // short-circuit: no fetch below
|
||||
} else {
|
||||
// unknown path → empty
|
||||
|
||||
setOpts([]);
|
||||
setLoading(false);
|
||||
return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue