Choices
Selects, radio groups, segmented controls, checkbox groups and toggle groups
Introduction
StellarAdmin provides five different kinds of editors for selecting items(s) from a range of options.
| Editor | Use it for |
|---|---|
UseSelectEditor() | Select a single item from a list. This is the default for enums and bool?. |
UseRadioGroupEditor() | Select a single value, with every option visible, and room for descriptions. |
UseSegmentedControlEditor() | Select a single value from two to five short options, displayed in a row. |
UseCheckboxGroupEditor() | Select multiple values from a list. Useful when the backing property is an array or collection. |
UseToggleGroupEditor() | Select a single or multiple values displayed as chips or buttons. Single or multiple selection depends on the type of the backing property. |










These choice editors display all the available options on the form. For long lists coming from a database table, such as customers or airports, use a lookup instead. See selecting a related record for selecting a single value, and selecting several related records for selecting multiple values.
Supplying the options
You can supply the items displayed to the user explicitly by calling the UseItems() method in the editor builder to supply the list of options.
using StellarAdmin.Resources.Editors;
fields.Add(guide => guide.HomeAirport).UseRadioGroupEditor(radio =>
{
radio.UseItems([
new ChoiceItem("LIS", "Lisbon"),
new ChoiceItem("KIX", "Kyoto"),
new ChoiceItem("CPT", "Cape Town"),
]);
});

In this case, the underlying property is nullable, so the radio group also has an empty option, "Not set". See changing the empty option.
A ChoiceItem requires a value and a title. Values are strings, and converted to the property's type when the form is saved. You can also set the following properties:
| Property | Use it for |
|---|---|
Description | Secondary text displayed below the option's title. |
Group | The ChoiceGroup the option belongs to. Only selects display groups, as option groups. |
Media | An icon, image or short code beside the title. See displaying an icon or image beside each option. |
Disabled | Displaying the option without allowing people to select it. |
UseItems() has a few different overloads:
| Overload | Use it for |
|---|---|
UseItems(items) | A fixed list of ChoiceItem or SelectListItem. |
UseItems((services, cancellationToken) => ...) | Useful for loading the options from a service that must be resolved via DI. |
UseItems<TProvider>() | A provider that implements IChoiceItemsProvider. Register the provider as a service. |
UseItems((form, services, cancellationToken) => ...) | Options that depend on other fields. See filtering options by another field. |
UseItems<TEntity>(value, title) | Rows of an EF Core entity that isn't a resource. The method is in the StellarAdmin.EntityFrameworkCore namespace. |
The example below loads the options from a service registered with dependency injection.
fields.Add(guide => guide.HomeAirport).UseSelectEditor(select =>
select.UseItems(async (services, cancellationToken) =>
{
var airports = services.GetRequiredService<AirportDirectory>();
return (await airports.ListAsync(cancellationToken))
.Select(airport => new ChoiceItem(airport.Code, airport.City))
.ToList();
}));Inferring options from the property type
When you don't call UseItems(), StellarAdmin will attempt to infer the options from the type of the property:
- Enums list their members. An enum with
[Flags]has no options. - Booleans get Yes and No.
- Collections of enums, such as
List<Climate>, list the members of the enum and allow users to select multiple items, so use them with a checkbox group or a toggle group.
Enums
StellarAdmin generates an option for each member of an enum. Use the [Display] attribute on each member to set the title of the option with Name, and its description with Description. You can set GroupName in the [Display] attribute to divide the options into groups (only displayed in select editors).
public enum TripDifficulty
{
[Display(Name = "Easy", Description = "Gentle walks, a few hours a day.")]
Easy,
[Display(Name = "Moderate", Description = "Full days on foot, some climbs.")]
Moderate,
[Display(Name = "Challenging", Description = "Long days and steep trails.")]
Challenging,
}Using the radio group editor with a property of type TripDifficulty will display the following:


When the property is a collection of an enum, StellarAdmin generates the same options, and people can select several of them. Use a checkbox group or a toggle group for these properties. In the example below, a trip has a list of climates:
public class Trip
{
public List<Climate> Climates { get; set; } = [];
}
public enum Climate
{
Tropical,
Arid,
Temperate,
Mediterranean,
Continental,
Polar,
Alpine,
}The checkbox group lists each member of Climate, and saves the checked ones to the list:
fields.Add(trip => trip.Climates).UseCheckboxGroupEditor();Use another resource as options
Call UseResource<TResource>() to list the records of another resource. Each option takes its title, description and media from that resource's title and reference information.
fields.Add(trip => trip.DestinationId).UseRadioGroupEditor(radio =>
radio.UseResource<Destination>());Foreign keys and many-to-many navigations on EF Core forms list the related resource's records without calling UseResource(). See selecting a related record and selecting several related records.
Displaying an icon or image beside each option
Each option can display an icon, image or short code beside its title, to help people recognize it at a glance. Set the Media of the ChoiceItem to the media you want to display.
fields.Add(trip => trip.Transport).UseToggleGroupEditor(toggle =>
{
toggle.UseItems([
new ChoiceItem("Plane", "Plane") { Media = new ItemMedia.Icon("plane") },
new ChoiceItem("Train", "Train") { Media = new ItemMedia.Icon("train-front") },
new ChoiceItem("Ship", "Ship") { Media = new ItemMedia.Icon("ship") },
]);
});

There are four kinds of media:
| Media | Displays |
|---|---|
new ItemMedia.Icon(name) | The icon with the specified name, in the text color. |
new ItemMedia.Avatar(url) | A round image from the specified URL. When the URL is null, the initials of the option's title. |
new ItemMedia.Image(url) | A square image from the specified URL, with rounded corners. |
new ItemMedia.Code(value) | A short code, such as an airport or currency code, as a badge. |
Radio groups, checkbox groups, segmented controls and toggle groups display the media. Selects only display the title, since a browser's native select cannot display images.
Configuring the empty option
The empty option is available when the user can clear or unset a value. It will be enabled by default on nullable types and will display the text "Not set" as its label. You can use the EmptyChoiceText property to change the label text, and EmptyChoice to change when the empty option is added.
fields.Add(trip => trip.LeadGuideId).UseSelectEditor(select =>
{
select.EmptyChoice = EmptyChoice.Include;
select.EmptyChoiceText = "No guide yet";
});| Value | Empty option |
|---|---|
EmptyChoice.Auto | Added when the property type is nullable. This is the default. |
EmptyChoice.Include | Always added, even when the value is required. |
EmptyChoice.Omit | Never added, even when the property is nullable. |
A select also displays the empty option while a required value matches no option, such as a new record's foreign key of 0, so that no other option appears selected. Once the value matches an option, the empty option no longer appears.
Changing the layout of the options
Columns
Radio groups and checkbox groups display their options in a single column. Call Columns() to spread the options over more columns.
fields.Add(trip => trip.Tags).UseCheckboxGroupEditor(tags =>
{
tags.Columns(3);
});With Columns(3), the options are displayed in one column when the field is narrow, and in three columns once the field is at least 40rem wide.


To set the number of columns at each width, use the same breakpoints as form layout:
tags.Columns(columns => columns.Small(2).Large(3));Options fill each row from left to right before starting the next. Set Flow to Down to fill each column from top to bottom instead, so that people can read an alphabetical list down each column.
using StellarAdmin.UI;
fields.Add(trip => trip.Tags).UseCheckboxGroupEditor(tags =>
{
tags.Columns(3);
tags.Flow = CheckboxGroupFlow.Down;
});Radio and Checkbox Cards
Radio groups and checkbox groups display a list of options with labels. Set Appearance to Cards to display each option as a selectable card instead, which leaves more room for a description and media.
The example below displays the trip's difficulty as cards in three columns, each with its title and description.
fields.Add(trip => trip.Difficulty).UseRadioGroupEditor(difficulty =>
{
difficulty.Appearance = RadioGroupAppearance.Cards;
difficulty.Columns(3);
});

Toggle groups
The toggle group supports 3 different appearances.
ToggleGroupAppearance | Displays |
|---|---|
Chips | Separate rounded chips, with a check mark on the selected ones. This is the default. |
Joined | Buttons joined into a single connected group. |
Buttons | Separate buttons. |






When a toggle group uses Chips, use CheckPlacement to specify where the chips display their check mark:
ToggleGroupCheckPlacement | Displays the check mark |
|---|---|
ReplaceMedia | In place of the option's media, so the chip keeps its width. Before the title when the option has no media. This is the default. |
Start | Before the media and title. |
End | After the title. |
fields.Add(guide => guide.Languages).UseToggleGroupEditor(languages =>
{
languages.Appearance = ToggleGroupAppearance.Chips;
languages.CheckPlacement = ToggleGroupCheckPlacement.End;
});