Skip to content

Commit db31f99

Browse files
committed
Fix field mapping in ObjectForm to support both array and object formats for schema fields
1 parent b86b41d commit db31f99

2 files changed

Lines changed: 22 additions & 10 deletions

File tree

apps/console/src/App.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,11 @@ export function AppContent() {
208208
recordId: editingRecord?.id,
209209
layout: 'vertical',
210210
columns: 1,
211-
fields: Array.isArray(currentObjectDef.fields)
212-
? currentObjectDef.fields.map((f: any) => f.name)
213-
: Object.keys(currentObjectDef.fields || {}).map(k => k), /* Ensure all keys are mapped */
211+
// FIX: fields property should be array of strings, but currentObjectDef.fields might be an object
212+
// Explicitly map all keys to ensure we include all fields
213+
fields: currentObjectDef.fields && !Array.isArray(currentObjectDef.fields)
214+
? Object.keys(currentObjectDef.fields)
215+
: (currentObjectDef.fields || []).map((f: any) => typeof f === 'string' ? f : f.name),
214216
onSuccess: () => { setIsDialogOpen(false); navigate(location.pathname); },
215217
onCancel: () => setIsDialogOpen(false),
216218
showSubmit: true,

packages/plugin-form/src/ObjectForm.tsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,23 +155,33 @@ export const ObjectForm: React.FC<ObjectFormProps> = ({
155155
// Determine which fields to include
156156
const fieldsToShow = schema.fields || Object.keys(objectSchema.fields || {});
157157

158-
fieldsToShow.forEach((fieldName) => {
159-
const field = objectSchema.fields?.[fieldName];
160-
if (!field) return;
158+
// Support object format for fields in schema (legacy/compat)
159+
const fieldNames = Array.isArray(fieldsToShow)
160+
? fieldsToShow
161+
: Object.keys(fieldsToShow);
162+
163+
fieldNames.forEach((fieldName) => {
164+
// If fieldsToShow is an array of strings, fieldName is the string
165+
// If fieldsToShow is array of objects (unlikely but possible in some formats), we need to extract name
166+
const name = typeof fieldName === 'string' ? fieldName : (fieldName as any).name;
167+
if (!name) return;
168+
169+
const field = objectSchema.fields?.[name];
170+
if (!field && !hasInlineFields) return; // Skip if not found in object definition unless inline
161171

162172
// Check field-level permissions for create/edit modes
163-
const hasWritePermission = !field.permissions || field.permissions.write !== false;
173+
const hasWritePermission = !field?.permissions || field?.permissions.write !== false;
164174
if (schema.mode !== 'view' && !hasWritePermission) return; // Skip fields without write permission
165175

166176
// Check if there's a custom field configuration
167-
const customField = schema.customFields?.find(f => f.name === fieldName);
177+
const customField = schema.customFields?.find(f => f.name === name);
168178

169179
if (customField) {
170180
generatedFields.push(customField);
171-
} else {
181+
} else if (field) {
172182
// Auto-generate field from schema
173183
const formField: FormField = {
174-
name: fieldName,
184+
name: name,
175185
label: field.label || fieldName,
176186
type: mapFieldTypeToFormType(field.type),
177187
required: field.required || false,

0 commit comments

Comments
 (0)