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
property icon AfterControlTemplate ITemplate Gets or sets a template rendering contents of the suffix.
attribute
inner element
static value
bindable
default
null
property icon AutoGenerateValidator Boolean Gets or sets a validation should be displayed
attribute
inner element
static value
bindable
default
True
property icon BeforeControlTemplate ITemplate Gets or sets a template rendering contents of the suffix.
attribute
inner element
static value
bindable
default
null
property icon Control DotvvmControl Gets or sets a template rendering contents of the label.
attribute
inner element
static value
bindable
default
null
property icon HintTemplate ITemplate Gets or sets a template rendering contents of the hint.
attribute
inner element
static value
bindable
default
null
property icon HintText String Gets or sets the hint inside the label.
attribute
inner element
static value
bindable
default
null
property icon LabelTemplate ITemplate Gets or sets a template rendering contents of the label.
attribute
inner element
static value
bindable
default
null
property icon LabelText String Gets or sets the text displayed inside the label.
attribute
inner element
static value
bindable
default
null
property icon ShowValidationIcon Boolean Gets or sets a validation should have a icon
attribute
inner element
static value
bindable
default
True
property icon ValidationIcon IconBase Gets or sets the icon displayed in the validation.
attribute
inner element
static value
bindable
default
null
property icon ValidatorPosition ValidatorPosition ValidatorPosition Gets or sets where a validation should be displayed
attribute
inner element
static value
bindable
default
Before
property icon Visible Boolean
attribute
inner element
static value
bindable
default
True

HTML produced by the control