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
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
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
Disabled
获得 组件是否被禁用属性值
protected string? Disabled { get; }
Property Value
EditContext
Gets the associated EditContext.
protected EditContext? EditContext { get; set; }
Property Value
ErrorMessage
获得/设置 错误描述信息
protected string? ErrorMessage { get; set; }
Property Value
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
IsAsyncValidate
获得/设置 是否执行了自定义异步验证
protected bool IsAsyncValidate { get; set; }
Property Value
IsDisabled
获得/设置 是否禁用 默认为 false
[Parameter]
public bool IsDisabled { get; set; }
Property Value
IsNeedValidate
获得/设置 是否不进行验证 默认为 false
public bool IsNeedValidate { get; }
Property Value
IsValid
获得/设置 组件是否合规 默认为 null 未检查
protected bool? IsValid { get; set; }
Property Value
- bool?
OnValueChanged
获得/设置 Value 改变时回调方法
[Parameter]
public Func<TValue, Task>? OnValueChanged { get; set; }
Property Value
ParsingErrorMessage
获得/设置 类型转化失败格式化字符串 默认为 null
[Parameter]
public string? ParsingErrorMessage { get; set; }
Property Value
PreviousErrorMessage
获得/设置 上一次转化失败错误描述信息
protected string? PreviousErrorMessage { get; set; }
Property Value
PreviousParsingAttemptFailed
获得/设置 上一次转化是否失败 为 true 时表示上一次转化失败
protected bool PreviousParsingAttemptFailed { get; set; }
Property Value
Required
是否显示 必填项标记
protected string? Required { get; set; }
Property Value
Rules
获得 数据验证方法集合
protected List<IValidator> Rules { get; }
Property Value
SkipValidate
获得/设置 是否不进行验证 默认为 false
[Parameter]
public bool SkipValidate { get; set; }
Property Value
ValidCss
获得/设置 数据合规样式
protected string? ValidCss { get; }
Property Value
ValidateRules
获得/设置 自定义验证集合
[Parameter]
public List<IValidator>? ValidateRules { get; set; }
Property Value
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
FormatParsingErrorMessage()
protected virtual string? FormatParsingErrorMessage()
Returns
IsComplexValue(object?)
判断是否需要进行复杂类验证
public virtual bool IsComplexValue(object? value)
Parameters
value
object
Returns
IsRequired()
判断是否为必填字段
protected virtual bool IsRequired()
Returns
OnAfterRenderAsync(bool)
OnAfterRender 方法
protected override Task OnAfterRenderAsync(bool firstRender)
Parameters
firstRender
bool
Returns
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
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
SetValue(TValue)
设置 Value 值
public void SetValue(TValue value)
Parameters
value
TValue
ShowValidResult()
增加客户端 Tooltip 方法
protected virtual ValueTask ShowValidResult()
Returns
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
stringThe string value to be parsed.
result
TValueAn instance of
TValue
.validationErrorMessage
stringIf 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
objectcontext
ValidationContextresults
List<ValidationResult>