diff --git a/src/MatBlazor/Components/Base/BaseMatInputComponent.cs b/src/MatBlazor/Components/Base/BaseMatInputComponent.cs index e975da30..6f9c27a5 100644 --- a/src/MatBlazor/Components/Base/BaseMatInputComponent.cs +++ b/src/MatBlazor/Components/Base/BaseMatInputComponent.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Forms; using System; using System.Collections.Generic; @@ -80,7 +80,13 @@ protected void NotifyFieldChanged() /// Gets or sets an expression that identifies the bound value. /// [Parameter] - public Expression> ValueExpression { get; set; } + public Expression> ValueExpression { get; set; } + + /// + /// Gets or sets an expression that identifies the bound value to validate. + /// + [Parameter] + public Expression> ValidateValueExpression { get; set; } /// public override Task SetParametersAsync(ParameterView parameters) @@ -97,13 +103,13 @@ public override Task SetParametersAsync(ParameterView parameters) EditContext = CascadedEditContext; if (EditContext != null) { - if (ValueExpression == null) + if (ValueExpression == null && ValidateValueExpression == null) { - throw new InvalidOperationException($"{GetType()} requires a value for the 'ValueExpression' " + + throw new InvalidOperationException($"{GetType()} requires a value for the 'ValueExpression'" + $"parameter. Normally this is provided automatically when using 'bind-Value'."); } - FieldIdentifier = FieldIdentifier.Create(ValueExpression); + FieldIdentifier = FieldIdentifier.Create(ValidateValueExpression ?? ValueExpression); } _hasSetInitialEditContext = true; @@ -124,4 +130,4 @@ public override Task SetParametersAsync(ParameterView parameters) return base.SetParametersAsync(ParameterView.Empty); } } -} \ No newline at end of file +}