BuzzForm
BuzzFormDocs

Select Field

Dropdown select with search, multi-select, and clearable options.

Select Field

The select field renders a dropdown select with optional search and multi-select support.

Schema Properties

Prop

Type

UI Options

OptionTypeDefaultDescription
isClearablebooleantrue (when not required)Show a clear button when a value is selected
labelsobject-Text and label overrides
labels.emptyReactNode"No results found."Message shown when no options match
classNamestring-CSS class applied to the field container
widthstring | number-Inline width applied to the field

React Overrides: The label, description, and ui.labels.empty properties all support ReactNode (JSX) when importing defineSchema from @buildnbuzz/form-react.

Basic Usage

Single Select

const schema = defineSchema({
  fields: [
    {
      type: "select",
      name: "role",
      label: "Role",
      options: [
        { label: "Admin", value: "admin" },
        { label: "User", value: "user" },
        { label: "Guest", value: "guest" },
      ],
      required: true,
    },
  ],
});

Multi-Select

{
  type: "select",
  name: "interests",
  label: "Interests",
  hasMany: true,
  options: ["Design", "Development", "Marketing", "Sales"],
  minSelected: 1,
  maxSelected: 3,
}

Examples

With Clearable Options

{
  type: "select",
  name: "country",
  label: "Country",
  options: countries,
  ui: {
    isClearable: true,
    labels: {
      empty: "No country found",
    },
  },
}

With Option Descriptions

{
  type: "select",
  name: "plan",
  label: "Plan",
  options: [
    { label: "Free", value: "free", ui: { description: "$0/month" } },
    { label: "Pro", value: "pro", ui: { description: "$29/month" } },
    { label: "Enterprise", value: "enterprise", ui: { description: "Custom pricing" } },
  ],
}

With Disabled Options

{
  type: "select",
  name: "region",
  label: "Region",
  options: [
    { label: "US", value: "us" },
    { label: "UK", value: "uk" },
    { label: "EU", value: "eu", disabled: true },
  ],
}

Dynamic Option Disabled

{
  type: "select",
  name: "state",
  label: "State",
  options: [
    { label: "California", value: "CA" },
    { label: "Texas", value: "TX", disabled: { $data: "/country", neq: "US" } },
  ],
}

Async Options with Resolvers

For options loaded from APIs, use the option resolver registry. This enables cascading dropdowns, loading states, and automatic dependency tracking:

const resolvers = defineOptionResolvers({
  listCountries: async () => {
    const res = await fetch("https://countriesnow.space/api/v0.1/countries");
    const json = await res.json();
    return json.data.map((c: { country: string }) => ({
      label: c.country,
      value: c.country,
    }));
  },
});

const schema = defineSchema({
  fields: [
    {
      type: "select",
      name: "country",
      label: "Country",
      options: { resolver: "listCountries" },
    },
  ],
});

// In your form:
<Form schema={schema} optionResolvers={resolvers}>
  <FormContent><FormFields /><FormSubmit /></FormContent>
</Form>

Cascading Dropdowns

Declare dependencies to re-fetch options when a parent field changes:

{
  type: "select",
  name: "state",
  label: "State",
  options: { resolver: "listStates" },
  dependencies: ["/country"],       // re-fetch when country changes
  disabled: { $data: "/country", not: true },  // disable until country selected
}

When a dependency changes, the system automatically:

  1. Clears the field value — prevents stale selections
  2. Re-fetches options — calls the resolver with latest values
  3. Updates loading state — shows loading indicator

See Option Resolvers for the full guide.

Auto-Derived Validators

PropertyValidator
required: truerequired
hasMany: true + minSelectedminSelected
hasMany: true + maxSelectedmaxSelected

On this page