You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using 2 validation rules ending with the same property name, e.g.
this.ValidationRule(
viewModel => viewModel.Origin.Name,
name => !string.IsNullOrWhiteSpace(name),
"You must specify a valid origin name");
this.ValidationRule(
viewModel => viewModel.Destination.Name,
name => !string.IsNullOrWhiteSpace(name),
"You must specify a valid destination name");
and then
this.BindValidation(ViewModel, vm => vm.Origin.Name, view => view.OriginNameError.Text);
this.BindValidation(ViewModel, vm => vm.Destination.Name, view => view.DestinationNameError.Text);
results in view.OriginNameError and view.DestinationNameError having all "*.Name" errors.
Steps To Reproduce
Use example mentioned before.
Expected behavior
Errors with the same last property name should not "share" errors.
I have fixed this bug by replacing all instances of "Body.GetMemberInfo().Name" in the code by "Body.GetPropertyPath()", which returns "Origin.Name" and "Destination.Name" instead of only the "Name".
I know you might be in the process of refactoring property validation, but if you are ready, I'll make a pull request.
GetPropertyPath code:
// <copyright file="ReactiveUI.Validation/src/ReactiveUI.Validation/Extensions/ExpressionExtensions.cs" company=".NET Foundation">
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
// </copyright>
using System.Linq.Expressions;
using System.Text;
namespace ReactiveUI.Validation.Extensions
{
/// <summary>
/// Extensions methods associated to <see cref="Expression"/> instances.
/// </summary>
public static class ExpressionExtensions
{
/// <summary>
/// Returns a property path expression as a string.
/// </summary>
/// <param name="expression">The property path expression.</param>
/// <returns>The property path string representing the expression.</returns>
public static string GetPropertyPath(this Expression expression)
{
var path = new StringBuilder();
while (expression is MemberExpression memberExpression)
{
if (path.Length > 0)
path.Insert(0, '.');
path.Insert(0, memberExpression.Member.Name);
expression = memberExpression.Expression;
}
return path.ToString();
}
}
}
The text was updated successfully, but these errors were encountered:
Describe the bug
Using 2 validation rules ending with the same property name, e.g.
and then
results in view.OriginNameError and view.DestinationNameError having all "*.Name" errors.
Steps To Reproduce
Use example mentioned before.
Expected behavior
Errors with the same last property name should not "share" errors.
Screenshots
Environment
but the bug is present on all platforms.
Additional context
I have fixed this bug by replacing all instances of "Body.GetMemberInfo().Name" in the code by "Body.GetPropertyPath()", which returns "Origin.Name" and "Destination.Name" instead of only the "Name".
I know you might be in the process of refactoring property validation, but if you are ready, I'll make a pull request.
GetPropertyPath code:
The text was updated successfully, but these errors were encountered: