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:
| Property | Editor |
|---|---|
string, Guid | Text 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 |
| Numbers | Number input |
DateOnly, DateTime, TimeOnly | Date, date and time, or time input |
DateTimeOffset | Text input that keeps the offset |
bool | Checkbox |
bool? | Select with Yes, No and Not set |
| Enum | Select 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 value | Dictionary 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:
| Editor | Method | Page |
|---|---|---|
| Text input | UseTextInputEditor() | Inputs |
| Textarea | UseTextareaEditor() | Inputs |
| Date, date and time, time | UseDateInputEditor(), UseDateTimeInputEditor(), UseTimeInputEditor() | Inputs |
| Checkbox, switch | UseCheckboxEditor(), UseToggleEditor() | Inputs |
| Slider | UseSliderEditor() | Inputs |
| One-time code | UseOneTimeCodeEditor() | Inputs |
| Select, radio group, segmented control | UseSelectEditor(), UseRadioGroupEditor(), UseSegmentedControlEditor() | Choices |
| Checkbox group, toggle group | UseCheckboxGroupEditor(), UseToggleGroupEditor() | Choices |
| List, dictionary | UseListEditor(), UseDictionaryEditor() | Lists and dictionaries |
| Lookup, multi-lookup | UseLookupSheetEditor(), UseMultiLookupSheetEditor() | Selecting a related record, selecting several related records |
| Image | UseImageEditor() | Images |
| Rich text | UseRichTextEditor() | Rich text |
| Icon | UseIconEditor() | 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:

