Overview

How StellarAdmin chooses a field's editor, and how to choose another

A field's editor is the control people use to enter the field's value, such as a text input or a checkbox. StellarAdmin derives the field's editor from the property's type and attributes. The table below lists the editor StellarAdmin chooses for each kind of property:

PropertyEditor
string, GuidText input
string with [EmailAddress], [Phone], [Url] or [DataType(DataType.Password)]Email, phone, URL or password input
string with [DataType(DataType.MultilineText)]Textarea
string with [DataType(DataType.Html)]Rich text editor
NumbersNumber input
DateOnly, DateTime, TimeOnlyDate, date and time, or time input
DateTimeOffsetText input that keeps the offset
boolCheckbox
bool?Select with Yes, No and Not set
EnumSelect of the enum's members
Enum with [Flags]Text input
List of strings or numbers, such as List<string> or int[]List editor
Dictionary with a string or enum key, and a string, number or enum valueDictionary editor
Foreign key to a registered resource (EF Core)Lookup
Many-to-many navigation to a registered resource (EF Core)Multi-lookup

Choosing another editor

You can change the default editor by calling one of the predefined Use...Editor() methods. Most editor methods have a callback parameter that allows further configuration of the editor.

The example below uses a textarea for the summary, a switch for IsPublished, and a slider for the group size:

fields.Add(trip => trip.Summary).UseTextareaEditor(textarea => textarea.Rows = 4);
fields.Add(trip => trip.IsPublished).UseToggleEditor();
fields.Add(trip => trip.MaxGroupSize).UseSliderEditor(slider =>
{
    slider.Min = 2;
    slider.Max = 16;
    slider.ValueFormat = "{0} people";
});

Some editor properties will derive their default values from the underlying field attribute, unless explicitly specified. For example, a slider's range can be specified by adding the [Range] attribute to the property.

Each editor's page lists its settings and their defaults:

EditorMethodPage
Text inputUseTextInputEditor()Inputs
TextareaUseTextareaEditor()Inputs
Date, date and time, timeUseDateInputEditor(), UseDateTimeInputEditor(), UseTimeInputEditor()Inputs
Checkbox, switchUseCheckboxEditor(), UseToggleEditor()Inputs
SliderUseSliderEditor()Inputs
One-time codeUseOneTimeCodeEditor()Inputs
Select, radio group, segmented controlUseSelectEditor(), UseRadioGroupEditor(), UseSegmentedControlEditor()Choices
Checkbox group, toggle groupUseCheckboxGroupEditor(), UseToggleGroupEditor()Choices
List, dictionaryUseListEditor(), UseDictionaryEditor()Lists and dictionaries
Lookup, multi-lookupUseLookupSheetEditor(), UseMultiLookupSheetEditor()Selecting a related record, selecting several related records
ImageUseImageEditor()Images
Rich textUseRichTextEditor()Rich text
IconUseIconEditor()Icons

If the editor you specify does not support the underlying data type, StellarAdmin will fall back to the property's default editor based on its data type.

You can also create your own custom editors.

Adding CSS classes

StellarAdmin allows you to pass CSS classes to the various editors via their ClassNames property. The ClassNames property will have various sub properties to target specific areas of the editor, such as the Root, Content, Label, Control, Description and Error.

The example below adds a class to the textarea of the trip's summary:

fields.Add(trip => trip.Summary).UseTextareaEditor(textarea =>
{
    textarea.ClassNames.Control = "trip-summary";
});

Define the class in a stylesheet in your app's wwwroot folder, and add the stylesheet with AddStylesheet(). The stylesheet below gives the summary a striped background, to mark it as a restricted field:

.trip-summary {
  border-color: rgb(217 119 6 / 0.7);
  background: repeating-linear-gradient(-45deg, rgb(245 158 11 / 0.12) 0 8px, transparent 8px 16px),
    var(--sa-color-field);
}
builder.Services.AddStellarAdmin(admin =>
{
    admin.AddStylesheet("~/css/trip-summary.css");
});

The trip's summary is then displayed with the striped background:

A trip's edit page with the Summary textarea's striped amber background and border

On this page