Bug Description
When using defineUserProfile() with a select field type, the dropdown renders in the admin UI but has no options. The radio type works correctly with the same configuration.
Steps to Reproduce
import { defineUserProfile } from '@sonicjs-cms/core'
defineUserProfile({
fields: [
{
name: 'plan',
label: 'Plan',
type: 'select',
options: ['free', 'monthly', 'annual', 'lifetime'],
default: 'free',
required: true,
}
]
})
- Define a user profile with a
select field as shown above
- Go to Admin → Users → Edit a user
- Observe the "Plan" dropdown is empty
Expected Behavior
The select dropdown should show "free", "monthly", "annual", "lifetime" as options.
Actual Behavior
The select dropdown renders but contains no options.
Root Cause
The toFieldDefinition() function in user-profiles/user-profile-templates.ts maps field.options to field_options.enum:
// toFieldDefinition() output:
field_options: {
enum: ['free', 'monthly', 'annual', 'lifetime'],
enumLabels: ['free', 'monthly', 'annual', 'lifetime']
}
But renderDynamicField() for case "select" reads from opts.options:
case "select":
const selectOptions = opts.options || []; // ← looks for opts.options, not opts.enum
The radio case correctly falls back to opts.enum:
case "radio":
const radioOptions = opts.options || (Array.isArray(opts.enum) ? opts.enum.map(...) : []);
Fix
Either:
- Update
toFieldDefinition() to also set field_options.options
- Update the
select case in renderDynamicField() to fall back to opts.enum, matching the radio case
Workaround
Use type: 'radio' instead of type: 'select', which correctly reads from opts.enum.
Environment
@sonicjs-cms/core: 2.12.1
Bug Description
When using
defineUserProfile()with aselectfield type, the dropdown renders in the admin UI but has no options. Theradiotype works correctly with the same configuration.Steps to Reproduce
selectfield as shown aboveExpected Behavior
The select dropdown should show "free", "monthly", "annual", "lifetime" as options.
Actual Behavior
The select dropdown renders but contains no options.
Root Cause
The
toFieldDefinition()function inuser-profiles/user-profile-templates.tsmapsfield.optionstofield_options.enum:But
renderDynamicField()forcase "select"reads fromopts.options:The
radiocase correctly falls back toopts.enum:Fix
Either:
toFieldDefinition()to also setfield_options.optionsselectcase inrenderDynamicField()to fall back toopts.enum, matching theradiocaseWorkaround
Use
type: 'radio'instead oftype: 'select', which correctly reads fromopts.enum.Environment
@sonicjs-cms/core: 2.12.1