Search K
Appearance
With a TextAreaField
you can represent longer text passages that require line breaks. Its underlying type is always a string
.
In our demo application we use a string
property to store descriptions for our camping products.
public class Product
{
[Key]
public int Id { get; init; }
[Required]
public string Description { get; set; }
}
You can add the field to a resource by adding it with the Fields()
method. We configure the field to be hidden on the index page as the text might take up too much space.
public override IList<IResourceFieldBuilder> Fields()
{
return
[
TextAreaField.Make("Description", nameof(Product.Description))
.HideOnIndex(),
];
}
We provide additional features for TextAreaField
, that can be configured after field initialization.
You may want to limit the possible input length for your users, which is useful in scenarios where you want to keep content concise and readable. By chaining MaxLength(int maxLength)
after field initialization you can limit the text input length to the specified amount of characters.
The default limit is 256 characters.
For longer text passages it can be useful to increase the height of the input field, so users will keep an overview of what they've already written. With chaining Rows(int rows)
after field initialization you can preset the number of rows the text area input should be displayed with.
The default number of rows is 2.
A TextAreaField
displays its value as text. For longer texts, it may be useful to hide them on the Index view.
In Create and Update views a user will see a text area input field, which can be expanded as the user sees fit.
The default visibility values are as follows:
Resource View | Default |
---|---|
Index | visible |
Create | visible |
Update | visible |
Details | visible |
You can change the visibility of the field for each view. Please note, however, that fields should remain visible on Create pages if the field is required by the entity model and if no default value is set.
A TextAreaField
can be made sortable by chaining a call to Sortable()
after adding the field. Sorting will be performed in alphanumeric order.
public override IList<IResourceFieldBuilder> Fields()
{
return
[
TextAreaField.Make("Description", nameof(Product.Description))
.HideOnIndex()
.Sortable(),
];
}
A TextAreaField
can be made searchable by adding the field to a search engine configuration.