Validator

in namespace DotVVM.Framework.Controls

Displays the asterisk or validation message for a specified field.

Usage & Scenarios

Displays the asterisk or validation message for a specified field.

Look at the Validation tutorial to see how the validation works.

Sample 1: Basic Validator

The Value property specifies which property will be validated. In the viewmodel, the Text property has the [Required] attribute.

The content inside the Validator control will be displayed when the field is not valid.

<p>
  <dot:TextBox Text="{value: Text}" />
  <dot:Validator Value="{value: Text}">This field is required!</dot:Validator>
</p>
<dot:Button Text="SEND" Click="{command: Send()}" />
using System.ComponentModel.DataAnnotations;

namespace DotvvmWeb.Views.Docs.Controls.builtin.ValidationMessage.sample1
{
    public class ViewModel
    {
        
        [Required]
        public string Text { get; set; }

        public void Send()
        {
            // do the job
        }
    }
}

Sample 2: CSS Classes for Invalid Values

The Validator has a property InvalidCssClass. If the field is not valid, the Validator control will get this CSS class.

You can also apply the Validator properties to other elements.

<p>
  <dot:TextBox Text="{value: Text}" />
  
  <dot:Validator Value="{value: Text}" 
                 InvalidCssClass="validation-error">
	*
  </dot:Validator>
</p>

<div Validator.InvalidCssClass="validation-error-row"
     Validator.Value="{value: Text2}"
     style="padding: 10px; width: 200px">
  <dot:TextBox Text="{value: Text2}" />
</div>

<dot:Button Text="SEND" Click="{command: Send()}" />
using System.ComponentModel.DataAnnotations;

namespace DotvvmWeb.Views.Docs.Controls.builtin.ValidationMessage.sample2
{
    public class ViewModel
    {

        [Required]
        public string Text { get; set; }

        [Required]
        public string Text2 { get; set; }


        public void Send()
        {
            // do the job
        }
    }
}

Sample 3: Error Message Texts

There are the ShowErrorMessageText and SetToolTipText properties. If they are set, the error message generated by the [Required] attribute will be displayed in the Validator control or set as a tool tip text.

<p>
  <dot:TextBox Text="{value: Text}" />
  <dot:Validator Value="{value: Text}" 
                 ShowErrorMessageText="true"/>
</p>

<div Validator.Value="{value: Text2}"
     Validator.SetToolTipText="true">
  <dot:TextBox Text="{value: Text2}" />
</div>

<dot:Button Text="SEND" Click="{command: Send()}" />
using System.ComponentModel.DataAnnotations;

namespace DotvvmWeb.Views.Docs.Controls.builtin.ValidationMessage.sample3
{
    public class ViewModel
    {

        [Required]
        public string Text { get; set; }

        [Required]
        public string Text2 { get; set; }


        public void Send()
        {
            // do the job
        }
    }
}

Properties

Name Type Description Notes Default Value
property icon HideWhenValid Boolean Gets or sets whether the control should be hidden even for valid values.
attribute
inner element
static value
bindable
default
False
property icon InvalidCssClass String Gets or sets the name of CSS class which is applied to the control when it is not valid.
attribute
inner element
static value
bindable
default
null
property icon SetToolTipText Boolean Gets or sets whether the title attribute should be set to the error message.
attribute
inner element
static value
bindable
default
False
property icon ShowErrorMessageText Boolean Gets or sets whether the error message text should be displayed.
attribute
inner element
static value
bindable
default
False
property icon Value Object Gets or sets a binding that points to the validated value.
attribute
inner element
static value
bindable
default
null

HTML produced by the control

If the Validator control is used as a stand-alone control, it renders a <span>.

<span data-bind="..."></span>

If the properties of Validator are used on another element, it only renders a data-bind attribute.

data-bind="..."