Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/MatBlazor/Components/Base/BaseMatInputComponent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -80,7 +80,13 @@ protected void NotifyFieldChanged()
/// Gets or sets an expression that identifies the bound value.
/// </summary>
[Parameter]
public Expression<Func<T>> ValueExpression { get; set; }
public Expression<Func<T>> ValueExpression { get; set; }

/// <summary>
/// Gets or sets an expression that identifies the bound value to validate.
/// </summary>
[Parameter]
public Expression<Func<T>> ValidateValueExpression { get; set; }

/// <inheritdoc />
public override Task SetParametersAsync(ParameterView parameters)
Expand All @@ -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;
Expand All @@ -124,4 +130,4 @@ public override Task SetParametersAsync(ParameterView parameters)
return base.SetParametersAsync(ParameterView.Empty);
}
}
}
}