3using Microsoft.AspNetCore.Components;
4using Microsoft.AspNetCore.Components.Forms;
6using System.Collections.Generic;
8using System.Linq.Expressions;
9using System.Threading.Tasks;
23 private FieldIdentifier _fieldIdentifier;
24 private EditContext _previousEditContext;
25 private EventHandler<FieldChangedEventArgs> _fieldChangedHandler;
26 private EventHandler<ValidationStateChangedEventArgs> _validationStateChangedHandler;
31 [Parameter]
public Expression<Func<PropertyType>>
For {
get;
set; }
35 [Parameter]
public string WrapperId {
get;
set; } =
"wrapper";
39 [Parameter]
public string WrapperClass {
get;
set; } =
"validation-messages";
43 [Parameter]
public string ErrorClass {
get;
set; } =
"text-danger";
47 [Parameter]
public string WarningClass {
get;
set; } =
"text-warning";
51 [Parameter]
public string InfoClass {
get;
set; } =
"text-info";
69 #region Event Handlers
77 _fieldChangedHandler = (sender, eventArgs) =>
OnFieldChanged(sender, eventArgs);
89 throw new InvalidOperationException(
91 nameof(CslaValidationMessages<string>), nameof(EditContext)));
96 throw new ArgumentNullException(nameof(
For));
99 _fieldIdentifier = FieldIdentifier.Create(
For);
118 if (eventArgs.FieldIdentifier.Equals(_fieldIdentifier))
132 IEnumerable<string> messages;
152 if (_previousEditContext !=
null)
155 _previousEditContext.OnFieldChanged -= _fieldChangedHandler;
156 _previousEditContext.OnValidationStateChanged -= _validationStateChangedHandler;
162 #region Message Retrieval
191 private IEnumerable<string> GetBrokenRuleMessages(
RuleSeverity severity)
193 IList<string> messages =
new List<string>();
197 objectUnderTest = _fieldIdentifier.Model as
ICheckRules;
198 if (objectUnderTest ==
null)
200 throw new ArgumentException(nameof(_fieldIdentifier.Model));
207 if (rule.
Property.Equals(_fieldIdentifier.FieldName, StringComparison.InvariantCultureIgnoreCase))
224 #region IDisposable Interface
238 protected virtual void Dispose(
bool disposing)
Validation message base type
IEnumerable< string > GetInfoMessages()
Get info messages
void Dispose()
Dispose the object
bool _validationInitiated
Value indicating whether validation is initiated
string InfoWrapperClass
Gets or sets the info wrapper class
string WarningWrapperClass
Gets or sets the warning wrapper class
string InfoClass
Gets or sets the info class
void DetachPreviousEventHandlers()
Detatch previous event handlers
Expression< Func< PropertyType > > For
Gets or sets the expression t use during validation
void OnValidationStateChanged(object sender, ValidationStateChangedEventArgs eventArgs)
On validation state changed method
override void OnInitialized()
On initialized method
string WrapperClass
Gets or sets the wrapper class
IEnumerable< string > GetErrorMessages()
Get error messages
override void OnParametersSet()
On parameters set method
void OnFieldChanged(object sender, FieldChangedEventArgs eventArgs)
On field changed method
EditContext CurrentEditContext
Gets or sets the current edit context
string ErrorClass
Gets or sets the error class
string WrapperId
Gets or sets the wrapper id
virtual void Dispose(bool disposing)
Dispose the object
string ErrorWrapperClass
Gets or sets the error wrapper class
IEnumerable< string > GetWarningMessages()
Get warning messages
string WarningClass
Gets or sets the warning class
A strongly-typed resource class, for looking up localized strings, etc.
static string CascadingEditContextRequiredException
Looks up a localized string similar to {0} requires a cascading parameter of type {1}.
Stores details about a specific broken business rule.
string Property
Provides access to the property affected by the broken rule.
string Description
Provides access to the description of the broken rule.
RuleSeverity Severity
Gets the severity of the broken rule.
Defines the common methods for any business object which exposes means to supress and check business ...
BrokenRulesCollection GetBrokenRules()
Gets the broken rules collection
RuleSeverity
Values for validation rule severities.