Skip to content

Select field in defineUserProfile shows no options in admin UI #763

@lane711

Description

@lane711

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,
    }
  ]
})
  1. Define a user profile with a select field as shown above
  2. Go to Admin → Users → Edit a user
  3. 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:

  1. Update toFieldDefinition() to also set field_options.options
  2. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions