FormItem
in namespace DotVVM.BusinessPack.Controls
Usage & Scenarios
FormItem groups one input with its label, an optional hint, and validation feedback. It associates the label with the input so clicking the label focuses the field.
Sample 1: Labeling and validating an input
Place the input directly inside FormItem and set LabelText and HintText. FormItem uses the input's validation binding to display errors.
Click Save with an empty field to see the required-field message, then enter a name and try again. ValidatorPosition="After" places the message after the input. Use ValidationIcon to replace the default icon, or ShowValidationIcon="false" to show only the message.
<bp:FormItem LabelText="Display name" HintText="This name appears on your profile."
ValidatorPosition="After" ShowValidationIcon="true">
<ValidationIcon><bp:Icon Icon="Danger" /></ValidationIcon>
<bp:TextBox Text="{value: Name}" />
</bp:FormItem>
<bp:Button Text="Save" Click="{command: SavedName = Name}" />
<p Visible="{value: SavedName != null}">Saved display name: {{value: SavedName}}</p>
using System.ComponentModel.DataAnnotations;
using DotVVM.Framework.ViewModel;
namespace DotvvmWeb.Views.Docs.Controls.businesspack.FormItem.sample1
{
public class ViewModel : DotvvmViewModelBase
{
[Required(ErrorMessage = "Enter a display name.")]
public string Name { get; set; }
public string SavedName { get; set; }
}
}
Sample 2: Adding context around a field
Use LabelTemplate and HintTemplate instead of plain text when the label or hint needs markup. BeforeControlTemplate and AfterControlTemplate show which parts of the address are fixed; only the subdomain is editable.
Control names the field explicitly. AutoGenerateValidator="false" omits the generated validator, not the validation rules on the viewmodel.
<bp:FormItem AutoGenerateValidator="false">
<LabelTemplate><strong>Site address</strong></LabelTemplate>
<HintTemplate>Choose a subdomain such as <code>team</code>.</HintTemplate>
<BeforeControlTemplate>https://</BeforeControlTemplate>
<Control><bp:TextBox Text="{value: Subdomain}" /></Control>
<AfterControlTemplate>.example.org</AfterControlTemplate>
</bp:FormItem>
<p>Address: https://{{value: Subdomain}}.example.org</p>
using DotVVM.Framework.ViewModel;
namespace DotvvmWeb.Views.Docs.Controls.businesspack.FormItem.sample2
{
public class ViewModel : DotvvmViewModelBase
{
public string Subdomain { get; set; } = "team";
}
}
Properties
| Name | Type | Description | Notes | Default Value | |
|---|---|---|---|---|---|
| AfterControlTemplate | ITemplate | Gets or sets a template rendering contents of the suffix. |
inner element
static value
|
null | |
| AutoGenerateValidator | Boolean | Gets or sets a validation should be displayed |
attribute
static value
|
True | |
| BeforeControlTemplate | ITemplate | Gets or sets a template rendering contents of the suffix. |
inner element
static value
|
null | |
| ClientIDMode | ClientIDMode | Gets or sets the client ID generation algorithm. |
attribute
static value
|
Static | |
| Control | DotvvmControl | Gets or sets a template rendering contents of the label. |
inner element
static value
default
|
null | |
| DataContext | Object | Gets or sets a data context for the control and its children. All value and command bindings are evaluated in context of this value. The DataContext is null in client-side templates. |
attribute
bindable
|
null | |
| HintTemplate | ITemplate | Gets or sets a template rendering contents of the hint. |
inner element
static value
|
null | |
| HintText | String | Gets or sets the hint inside the label. |
attribute
static value
bindable
|
null | |
| ID | String | Gets or sets the control client ID within its naming container. |
attribute
static value
bindable
|
null | |
| IncludeInPage | Boolean | Gets or sets whether the control is included in the DOM of the page. |
attribute
static value
bindable
|
True | |
| LabelTemplate | ITemplate | Gets or sets a template rendering contents of the label. |
inner element
static value
|
null | |
| LabelText | String | Gets or sets the text displayed inside the label. |
attribute
static value
bindable
|
null | |
| ShowValidationIcon | Boolean | Gets or sets a validation should have a icon |
attribute
static value
|
True | |
| ValidationIcon | IconBase | Gets or sets the icon displayed in the validation. |
inner element
static value
bindable
|
null | |
| ValidatorPosition | ValidatorPosition | Gets or sets where a validation should be displayed |
attribute
static value
|
Before | |
| Visible | Boolean |
attribute
bindable
|
True |