Table of Contents

Class RequiredValidationRule

Namespace
Kentico.Xperience.Admin.Base.Forms
Assembly
Kentico.Xperience.Admin.Base.dll

Validates whether value for the field was set.

[ValidationRuleAttribute(typeof(RequiredValidationRuleAttribute))]
public sealed class RequiredValidationRule : ValidationRule<RequiredValidationRuleProperties, object>, IValidationRule
Inheritance
object
RequiredValidationRule
Implements
Inherited Members
Extension Methods

Remarks

The rule considers null value, empty string or empty collection as invalid values.

Constructors

RequiredValidationRule(ILocalizationService)

Creates a new instance of RequiredValidationRule class.

public RequiredValidationRule(ILocalizationService localizationService)

Parameters

localizationService ILocalizationService

Properties

ClientRuleName

Gets the client rule name identifier.

public override string ClientRuleName { get; }

Property Value

string

DefaultErrorMessage

Defines default error message of the validation rule.

protected override string DefaultErrorMessage { get; }

Property Value

string

ErrorMessageFormatter

Defines a formatter function for error message.

protected override Func<string, string> ErrorMessageFormatter { get; }

Property Value

Func<string, string>

Remarks

Formatter is applied for DefaultErrorMessage or ErrorMessage. The custom error message defined by ErrorMessage is considered as a localized and formatted by the caller.

Methods

Validate(object, IFormFieldValueProvider)

Validates whether value is not null, empty string or empty collection.

public override Task<ValidationResult> Validate(object value, IFormFieldValueProvider formFieldValueProvider)

Parameters

value object

Value to be validated.

formFieldValueProvider IFormFieldValueProvider

Provider of values of other form fields for contextual validation.

Returns

Task<ValidationResult>

Returns the validation result.