fixes
This commit is contained in:
@@ -80,9 +80,9 @@ export default function GenericForm({
|
||||
const queryResult = queries[index];
|
||||
const dataArray = queryResult?.data && Array.isArray(queryResult.data) ? queryResult.data : (queryResult?.data?.data ?? []);
|
||||
console.log('Relation query result for', relName, 'raw:', queryResult?.data);
|
||||
map[relName] = dataArray;
|
||||
});
|
||||
console.log('Final relationDataMap:', map);
|
||||
console.log('Relation data for', relName, ':', dataArray.slice(0, 1));
|
||||
map[relName] = dataArray;
|
||||
});
|
||||
return map;
|
||||
}, [allRelations, queries]);
|
||||
|
||||
|
||||
@@ -3,14 +3,17 @@ import { getFieldOptions } from '../../utils/options';
|
||||
import { FieldComponentProps } from '../../types/overrides';
|
||||
|
||||
export default function RelationField({ field, value, onChange, disabled, relationDataMap = {} }: FieldComponentProps) {
|
||||
console.log('RelationField render', field.label, 'enumOption:', field.enumOption, 'value prop:', value);
|
||||
const relationName = field.relation ?? (field as any).refers;
|
||||
if (!relationName || !relationDataMap[relationName]) {
|
||||
if (!relationName || !relationDataMap[relationName]) {
|
||||
throw new Error(`Relation data for "${relationName}" is missing – cannot render options for field "${field.label}"`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const relationData = relationDataMap[relationName];
|
||||
const isArrayRelation = field.type === 'array';
|
||||
const options = getFieldOptions(field, relationData);
|
||||
console.log('Options for', field.label, 'keys:', options.map(o=>o.key));
|
||||
if (options.length === 0) {
|
||||
throw new Error(`No selectable options available for field "${field.label}" (relation "${relationName}")`);
|
||||
}
|
||||
@@ -19,12 +22,18 @@ export default function RelationField({ field, value, onChange, disabled, relati
|
||||
|
||||
const normalizedValue = (() => {
|
||||
if (isArrayRelation && Array.isArray(value)) {
|
||||
return value.map((v: any) => (v != null && typeof v === 'object' ? String(v[keyField] ?? '') : String(v)));
|
||||
return value.map((v: any) => {
|
||||
if (v != null && typeof v === 'object') {
|
||||
return String(v[keyField] ?? '');
|
||||
}
|
||||
return String(v);
|
||||
});
|
||||
}
|
||||
if (value != null && typeof value === 'object') {
|
||||
return String(value[keyField] ?? '');
|
||||
}
|
||||
return value ?? (isArrayRelation ? [] : "");
|
||||
// Primitive (number/string) – coerce to string for Select compatibility
|
||||
return value != null ? String(value) : (isArrayRelation ? [] : "");
|
||||
})();
|
||||
|
||||
return (
|
||||
@@ -38,10 +47,13 @@ export default function RelationField({ field, value, onChange, disabled, relati
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
disabled={disabled}
|
||||
renderValue={(selected: any) => {
|
||||
console.log('Select renderValue for', field.label, 'selected:', selected);
|
||||
if (isArrayRelation) {
|
||||
return (selected as string[]).map(k => options.find(o => o.key === k)?.value ?? k).join(', ');
|
||||
}
|
||||
return options.find(o => o.key === selected)?.value ?? selected;
|
||||
const display = options.find(o => o.key === selected)?.value ?? selected;
|
||||
console.log('Display value for', field.label, ':', display);
|
||||
return display;
|
||||
}}
|
||||
>
|
||||
{options.map((opt) => (
|
||||
|
||||
Reference in New Issue
Block a user