The textbox editor is the property editor that you will likely use the most in your content models. It renders a plain single-line or multiline text input.
The textbox editor also supports string collection property types (f.e. IList<string>
). In this case, a sortable list of textboxes is rendered.
Usage
You do not have to specify the textbox editor for string property types. The textbox editor can be further configured by decorating the property with other attributes. See below for some examples and which attributes apply to the textbox editor.
Example
The following example demonstrates textbox editor configuration.
public class SampleContent: IContentType
{
// By convention; single line text input, not required.
public string Title { get; set; }
// Required single line text input with custom validation message.
[Required]
public string RequiredText { get; set; }
// Multiline textarea, not resizable.
[Multiline(NoResize = true)]
public string IntroText { get; set; }
// Multiline textarea, maximum length 500 characters.
[MaxLength(500)]
[Multiline]
public string ParagraphText { get; set; }
// Single line 200 pixel text input with regular expression and prefix to the left.
[Width(200)]
[Prefix("@")]
[RegularExpression(@"^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$")]
public string EmailAddress { get; set; }
}
Default Convention
The textbox editor is the default editor for string
property types. Without any other configuration, a single-line text input will be displayed in the back office. The input will have no validation.
Attributes
The following attributes can be applied to the content model property to change the behavior of the textbox editor.
- Required attribute validates that the input is not empty.
- MinLength attribute validates the minimum string length for the input value.
- MaxLength attribute validates the maximum string length for the input value.
- Multiline attribute specifies that the textbox should be a multi-line (textarea) input.
- RegularExpression attribute validates the input against a regular expression.
- Width attribute specifies the pixel field width for the textbox editor.
- Prefix attribute specifies a prefix to display next to the editor.