DOT

VVM

 DOCS

Version: 1.0 | 1.1 |

Validator

in namespace DotVVM.Framework.Controls

Displays the asterisk or validation message for a specified field.

Properties

Name Type Description Notes Default Value
Attributes Dictionary<String,Object>
attribute
inner element
static value
bindable
default
ClientIDMode ClientIDMode Gets or sets the client ID generation algorithm.
attribute
inner element
static value
bindable
default
Static
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.
attribute
inner element
static value
bindable
default
HideWhenValid Boolean Gets or sets whether the control should be hidden even for valid values.
attribute
inner element
static value
bindable
default
False
ID String Gets or sets the unique control ID.
attribute
inner element
static value
bindable
default
InnerText String Gets or sets the inner text of the HTML element.
attribute
inner element
static value
bindable
default
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
SetToolTipText Boolean Gets or sets whether the title attribute should be set to the error message.
attribute
inner element
static value
bindable
default
False
ShowErrorMessageText Boolean Gets or sets whether the error message text should be displayed.
attribute
inner element
static value
bindable
default
False
Value Object Gets or sets a binding that points to the validated value.
attribute
inner element
static value
bindable
default
Visible Boolean Gets or sets whether the control is visible.
attribute
inner element
static value
bindable
default
True

Events

Name Type Description

Usage & Scenarios

Displays the asterisk or validation message for a specified field.

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

HTML Rendered 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="..."

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 requied!</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
        }
    }
}

Suggestions


Help & Contribute

The documentation is maintained on GitHub.
We'll be happy if you edit the page and create a pull request.

Send message