Table of Contents

Class ValidateBase<TValue>

Namespace
BootstrapBlazor.Components
Assembly
BootstrapBlazor.dll

支持客户端验证的文本框基类

public abstract class ValidateBase<TValue> : DisplayBase<TValue>, IComponent, IHandleAfterRender, IHandleEvent, IAsyncDisposable, IValidateComponent

Type Parameters

TValue
Inheritance
DisplayBase<TValue>
ValidateBase<TValue>
Implements
Derived
Inherited Members
Extension Methods

Constructors

ValidateBase()

protected ValidateBase()

Properties

CascadedEditContext

获得 父组件的 EditContext 实例

[CascadingParameter]
protected EditContext? CascadedEditContext { get; set; }

Property Value

EditContext

CssClass

Gets a CSS class string that combines the class attribute and FieldClass properties. Derived components should typically use this value for the primary HTML element's 'class' attribute.

protected string? CssClass { get; }

Property Value

string

CurrentValue

Gets or sets the current value of the input.

protected TValue CurrentValue { get; set; }

Property Value

TValue

CurrentValueAsString

Gets or sets the current value of the input, represented as a string.

protected string CurrentValueAsString { get; set; }

Property Value

string

Disabled

获得 组件是否被禁用属性值

protected string? Disabled { get; }

Property Value

string

EditContext

Gets the associated EditContext.

protected EditContext? EditContext { get; set; }

Property Value

EditContext

ErrorMessage

获得/设置 错误描述信息

protected string? ErrorMessage { get; set; }

Property Value

string

FieldClass

Gets a string that indicates the status of the field being edited. This will include some combination of "modified", "valid", or "invalid", depending on the status of the field.

protected string FieldClass { get; }

Property Value

string

IsAsyncValidate

获得/设置 是否执行了自定义异步验证

protected bool IsAsyncValidate { get; set; }

Property Value

bool

IsDisabled

获得/设置 是否禁用 默认为 false

[Parameter]
public bool IsDisabled { get; set; }

Property Value

bool

IsNeedValidate

获得/设置 是否不进行验证 默认为 false

public bool IsNeedValidate { get; }

Property Value

bool

IsValid

获得/设置 组件是否合规 默认为 null 未检查

protected bool? IsValid { get; set; }

Property Value

bool?

OnValueChanged

获得/设置 Value 改变时回调方法

[Parameter]
public Func<TValue, Task>? OnValueChanged { get; set; }

Property Value

Func<TValue, Task>

ParsingErrorMessage

获得/设置 类型转化失败格式化字符串 默认为 null

[Parameter]
public string? ParsingErrorMessage { get; set; }

Property Value

string

PreviousErrorMessage

获得/设置 上一次转化失败错误描述信息

protected string? PreviousErrorMessage { get; set; }

Property Value

string

PreviousParsingAttemptFailed

获得/设置 上一次转化是否失败 为 true 时表示上一次转化失败

protected bool PreviousParsingAttemptFailed { get; set; }

Property Value

bool

Required

是否显示 必填项标记

protected string? Required { get; set; }

Property Value

string

Rules

获得 数据验证方法集合

protected List<IValidator> Rules { get; }

Property Value

List<IValidator>

SkipValidate

获得/设置 是否不进行验证 默认为 false

[Parameter]
public bool SkipValidate { get; set; }

Property Value

bool

ValidCss

获得/设置 数据合规样式

protected string? ValidCss { get; }

Property Value

string

ValidateRules

获得/设置 自定义验证集合

[Parameter]
public List<IValidator>? ValidateRules { get; set; }

Property Value

List<IValidator>

Methods

DisposeAsync(bool)

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.

protected override ValueTask DisposeAsync(bool disposing)

Parameters

disposing bool

Returns

ValueTask

FormatParsingErrorMessage()

protected virtual string? FormatParsingErrorMessage()

Returns

string

IsComplexValue(object?)

判断是否需要进行复杂类验证

public virtual bool IsComplexValue(object? value)

Parameters

value object

Returns

bool

IsRequired()

判断是否为必填字段

protected virtual bool IsRequired()

Returns

bool

OnAfterRenderAsync(bool)

OnAfterRender 方法

protected override Task OnAfterRenderAsync(bool firstRender)

Parameters

firstRender bool

Returns

Task

OnInitialized()

OnInitialized 方法

protected override void OnInitialized()

OnParametersSet()

OnParametersSet 方法

protected override void OnParametersSet()

OnValidate(bool?)

客户端检查完成时调用此方法

protected virtual void OnValidate(bool? valid)

Parameters

valid bool?

检查结果

RemoveValidResult(string?)

移除客户端 Tooltip 方法

protected virtual ValueTask RemoveValidResult(string? validateId = null)

Parameters

validateId string

Returns

ValueTask

SetDisable(bool)

设置是否可用状态

public void SetDisable(bool disable)

Parameters

disable bool

SetLabel(string)

设置 Label 值

public void SetLabel(string label)

Parameters

label string

SetParametersAsync(ParameterView)

SetParametersAsync 方法

public override Task SetParametersAsync(ParameterView parameters)

Parameters

parameters ParameterView

Returns

Task

SetValue(TValue)

设置 Value 值

public void SetValue(TValue value)

Parameters

value TValue

ShowValidResult()

增加客户端 Tooltip 方法

protected virtual ValueTask ShowValidResult()

Returns

ValueTask

ToggleMessage(IEnumerable<ValidationResult>, bool)

显示/隐藏验证结果方法

public virtual void ToggleMessage(IEnumerable<ValidationResult> results, bool validProperty)

Parameters

results IEnumerable<ValidationResult>
validProperty bool

是否对本属性进行数据验证

TryParseValueFromString(string, out TValue, out string?)

Parses a string to create an instance of TValue. Derived classes can override this to change how CurrentValueAsString interprets incoming values.

protected virtual bool TryParseValueFromString(string value, out TValue result, out string? validationErrorMessage)

Parameters

value string

The string value to be parsed.

result TValue

An instance of TValue.

validationErrorMessage string

If the value could not be parsed, provides a validation error message.

Returns

bool

True if the value could be parsed; otherwise false.

ValidatePropertyAsync(object?, ValidationContext, List<ValidationResult>)

属性验证方法

public Task ValidatePropertyAsync(object? propertyValue, ValidationContext context, List<ValidationResult> results)

Parameters

propertyValue object
context ValidationContext
results List<ValidationResult>

Returns

Task