From 03e1e0e9bc785fafb883b3a2729eb68d741531a5 Mon Sep 17 00:00:00 2001 From: Sebastian Mayer Date: Mon, 30 Sep 2019 15:50:40 +0200 Subject: [PATCH] provide possibility to override expression used for validation --- .../Components/Base/BaseMatInputComponent.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) 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 +}