Search K
Appearance
With a TextField
you can represent alphanumeric text in a resource. Its underlying type is always a string
.
In our demo application we use a string
property to store an employee's full name.
public class Employee
{
[Key]
public int Id { get; init; }
[Required]
public string Name { get; set; }
}
You can add the field to a resource by adding it with the Fields()
method.
public override IList<IResourceFieldBuilder> Fields()
{
return
[
TextField.Make("Name", nameof(Employee.Name)),
];
}
We provide additional features for TextField
, 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 number of characters.
The default limit is 64 characters.
A TextField
can be set as display name of an entity, by chaining AsDisplayName()
after field initialization. You can choose more than one field for the display name. Please note that the order the fields are added in is also the order of the display name parts.
public override IList<IResourceFieldBuilder> Fields()
{
return
[
TextField.Make("Name", nameof(Employee.Name))
.AsDisplayName(),
];
}
Setting a display name results in the following behavior in the UI:
A TextField
displays its value as text.
In Create and Update views a user will see a text input field.
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 TextField
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
[
TextField.Make("Name", nameof(Employee.Name))
.Sortable(),
];
}
A TextField
can be made searchable by adding the field to a search engine configuration.