diff --git a/src/Components/Components/ref/Microsoft.AspNetCore.Components.netstandard2.0.cs b/src/Components/Components/ref/Microsoft.AspNetCore.Components.netstandard2.0.cs index a4d8a9c9be..c9276fab24 100644 --- a/src/Components/Components/ref/Microsoft.AspNetCore.Components.netstandard2.0.cs +++ b/src/Components/Components/ref/Microsoft.AspNetCore.Components.netstandard2.0.cs @@ -419,8 +419,10 @@ namespace Microsoft.AspNetCore.Components.Forms public Microsoft.AspNetCore.Components.Forms.FieldIdentifier Field(string fieldName) { throw null; } public System.Collections.Generic.IEnumerable GetValidationMessages() { throw null; } public System.Collections.Generic.IEnumerable GetValidationMessages(Microsoft.AspNetCore.Components.Forms.FieldIdentifier fieldIdentifier) { throw null; } + public System.Collections.Generic.IEnumerable GetValidationMessages(System.Linq.Expressions.Expression> accessor) { throw null; } public bool IsModified() { throw null; } public bool IsModified(in Microsoft.AspNetCore.Components.Forms.FieldIdentifier fieldIdentifier) { throw null; } + public bool IsModified(System.Linq.Expressions.Expression> accessor) { throw null; } public void MarkAsUnmodified() { } public void MarkAsUnmodified(in Microsoft.AspNetCore.Components.Forms.FieldIdentifier fieldIdentifier) { } public void NotifyFieldChanged(in Microsoft.AspNetCore.Components.Forms.FieldIdentifier fieldIdentifier) { } @@ -431,24 +433,20 @@ namespace Microsoft.AspNetCore.Components.Forms { public static Microsoft.AspNetCore.Components.Forms.EditContext AddDataAnnotationsValidation(this Microsoft.AspNetCore.Components.Forms.EditContext editContext) { throw null; } } - public static partial class EditContextExpressionExtensions + public sealed partial class FieldChangedEventArgs : System.EventArgs { - public static System.Collections.Generic.IEnumerable GetValidationMessages(this Microsoft.AspNetCore.Components.Forms.EditContext editContext, System.Linq.Expressions.Expression> accessor) { throw null; } - public static bool IsModified(this Microsoft.AspNetCore.Components.Forms.EditContext editContext, System.Linq.Expressions.Expression> accessor) { throw null; } - } - public sealed partial class FieldChangedEventArgs - { - internal FieldChangedEventArgs() { } + public FieldChangedEventArgs(in Microsoft.AspNetCore.Components.Forms.FieldIdentifier fieldIdentifier) { } public Microsoft.AspNetCore.Components.Forms.FieldIdentifier FieldIdentifier { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } } } [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)] - public readonly partial struct FieldIdentifier + public readonly partial struct FieldIdentifier : System.IEquatable { private readonly object _dummy; public FieldIdentifier(object model, string fieldName) { throw null; } public string FieldName { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } } public object Model { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } } public static Microsoft.AspNetCore.Components.Forms.FieldIdentifier Create(System.Linq.Expressions.Expression> accessor) { throw null; } + public bool Equals(Microsoft.AspNetCore.Components.Forms.FieldIdentifier otherIdentifier) { throw null; } public override bool Equals(object obj) { throw null; } public override int GetHashCode() { throw null; } } @@ -457,24 +455,23 @@ namespace Microsoft.AspNetCore.Components.Forms public ValidationMessageStore(Microsoft.AspNetCore.Components.Forms.EditContext editContext) { } public System.Collections.Generic.IEnumerable this[Microsoft.AspNetCore.Components.Forms.FieldIdentifier fieldIdentifier] { get { throw null; } } public System.Collections.Generic.IEnumerable this[System.Linq.Expressions.Expression> accessor] { get { throw null; } } + public void Add(in Microsoft.AspNetCore.Components.Forms.FieldIdentifier fieldIdentifier, System.Collections.Generic.IEnumerable messages) { } public void Add(in Microsoft.AspNetCore.Components.Forms.FieldIdentifier fieldIdentifier, string message) { } - public void AddRange(in Microsoft.AspNetCore.Components.Forms.FieldIdentifier fieldIdentifier, System.Collections.Generic.IEnumerable messages) { } + public void Add(System.Linq.Expressions.Expression> accessor, System.Collections.Generic.IEnumerable messages) { } + public void Add(System.Linq.Expressions.Expression> accessor, string message) { } public void Clear() { } public void Clear(in Microsoft.AspNetCore.Components.Forms.FieldIdentifier fieldIdentifier) { } + public void Clear(System.Linq.Expressions.Expression> accessor) { } } - public static partial class ValidationMessageStoreExpressionExtensions + public sealed partial class ValidationRequestedEventArgs : System.EventArgs { - public static void Add(this Microsoft.AspNetCore.Components.Forms.ValidationMessageStore store, System.Linq.Expressions.Expression> accessor, string message) { } - public static void AddRange(this Microsoft.AspNetCore.Components.Forms.ValidationMessageStore store, System.Linq.Expressions.Expression> accessor, System.Collections.Generic.IEnumerable messages) { } - public static void Clear(this Microsoft.AspNetCore.Components.Forms.ValidationMessageStore store, System.Linq.Expressions.Expression> accessor) { } + public static readonly new Microsoft.AspNetCore.Components.Forms.ValidationRequestedEventArgs Empty; + public ValidationRequestedEventArgs() { } } - public sealed partial class ValidationRequestedEventArgs + public sealed partial class ValidationStateChangedEventArgs : System.EventArgs { - internal ValidationRequestedEventArgs() { } - } - public sealed partial class ValidationStateChangedEventArgs - { - internal ValidationStateChangedEventArgs() { } + public static readonly new Microsoft.AspNetCore.Components.Forms.ValidationStateChangedEventArgs Empty; + public ValidationStateChangedEventArgs() { } } } namespace Microsoft.AspNetCore.Components.Rendering diff --git a/src/Components/Components/src/Forms/EditContext.cs b/src/Components/Components/src/Forms/EditContext.cs index fd09a241f4..caaf677c37 100644 --- a/src/Components/Components/src/Forms/EditContext.cs +++ b/src/Components/Components/src/Forms/EditContext.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Linq.Expressions; namespace Microsoft.AspNetCore.Components.Forms { @@ -158,6 +159,16 @@ namespace Microsoft.AspNetCore.Components.Forms } } + /// + /// Gets the current validation messages for the specified field. + /// + /// This method does not perform validation itself. It only returns messages determined by previous validation actions. + /// + /// Identifies the field whose current validation messages should be returned. + /// The current validation messages for the specified field. + public IEnumerable GetValidationMessages(Expression> accessor) + => GetValidationMessages(FieldIdentifier.Create(accessor)); + /// /// Determines whether the specified fields in this has been modified. /// @@ -167,6 +178,14 @@ namespace Microsoft.AspNetCore.Components.Forms ? state.IsModified : false; + /// + /// Determines whether the specified fields in this has been modified. + /// + /// Identifies the field whose current validation messages should be returned. + /// True if the field has been modified; otherwise false. + public bool IsModified(Expression> accessor) + => IsModified(FieldIdentifier.Create(accessor)); + /// /// Validates this . /// diff --git a/src/Components/Components/src/Forms/EditContextDataAnnotationsExtensions.cs b/src/Components/Components/src/Forms/EditContextDataAnnotationsExtensions.cs index 6542114a8d..9fce473a41 100644 --- a/src/Components/Components/src/Forms/EditContextDataAnnotationsExtensions.cs +++ b/src/Components/Components/src/Forms/EditContextDataAnnotationsExtensions.cs @@ -74,7 +74,7 @@ namespace Microsoft.AspNetCore.Components.Forms Validator.TryValidateProperty(propertyValue, validationContext, results); messages.Clear(fieldIdentifier); - messages.AddRange(fieldIdentifier, results.Select(result => result.ErrorMessage)); + messages.Add(fieldIdentifier, results.Select(result => result.ErrorMessage)); // We have to notify even if there were no messages before and are still no messages now, // because the "state" that changed might be the completion of some async validation task diff --git a/src/Components/Components/src/Forms/EditContextExpressionExtensions.cs b/src/Components/Components/src/Forms/EditContextExpressionExtensions.cs deleted file mode 100644 index 3d856e241f..0000000000 --- a/src/Components/Components/src/Forms/EditContextExpressionExtensions.cs +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.Linq.Expressions; - -namespace Microsoft.AspNetCore.Components.Forms -{ - /// - /// Provides extension methods to simplify using with expressions. - /// - public static class EditContextExpressionExtensions - { - /// - /// Gets the current validation messages for the specified field. - /// - /// This method does not perform validation itself. It only returns messages determined by previous validation actions. - /// - /// The . - /// Identifies the field whose current validation messages should be returned. - /// The current validation messages for the specified field. - public static IEnumerable GetValidationMessages(this EditContext editContext, Expression> accessor) - => editContext.GetValidationMessages(FieldIdentifier.Create(accessor)); - - /// - /// Determines whether the specified fields in this has been modified. - /// - /// The . - /// Identifies the field whose current validation messages should be returned. - /// True if the field has been modified; otherwise false. - public static bool IsModified(this EditContext editContext, Expression> accessor) - => editContext.IsModified(FieldIdentifier.Create(accessor)); - } -} diff --git a/src/Components/Components/src/Forms/FieldChangedEventArgs.cs b/src/Components/Components/src/Forms/FieldChangedEventArgs.cs index 9bf18dd486..780a91a01d 100644 --- a/src/Components/Components/src/Forms/FieldChangedEventArgs.cs +++ b/src/Components/Components/src/Forms/FieldChangedEventArgs.cs @@ -1,21 +1,27 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; + namespace Microsoft.AspNetCore.Components.Forms { /// /// Provides information about the event. /// - public sealed class FieldChangedEventArgs + public sealed class FieldChangedEventArgs : EventArgs { + /// + /// Creates a new instance of . + /// + /// The + public FieldChangedEventArgs(in FieldIdentifier fieldIdentifier) + { + FieldIdentifier = fieldIdentifier; + } + /// /// Identifies the field whose value has changed. /// public FieldIdentifier FieldIdentifier { get; } - - internal FieldChangedEventArgs(in FieldIdentifier fieldIdentifier) - { - FieldIdentifier = fieldIdentifier; - } } } diff --git a/src/Components/Components/src/Forms/FieldIdentifier.cs b/src/Components/Components/src/Forms/FieldIdentifier.cs index a113cccbe7..fa3fb72dad 100644 --- a/src/Components/Components/src/Forms/FieldIdentifier.cs +++ b/src/Components/Components/src/Forms/FieldIdentifier.cs @@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Components.Forms /// Uniquely identifies a single field that can be edited. This may correspond to a property on a /// model object, or can be any other named value. /// - public readonly struct FieldIdentifier + public readonly struct FieldIdentifier : IEquatable { /// /// Initializes a new instance of the structure. @@ -68,8 +68,15 @@ namespace Microsoft.AspNetCore.Components.Forms /// public override bool Equals(object obj) => obj is FieldIdentifier otherIdentifier - && otherIdentifier.Model == Model - && string.Equals(otherIdentifier.FieldName, FieldName, StringComparison.Ordinal); + && Equals(otherIdentifier); + + /// + public bool Equals(FieldIdentifier otherIdentifier) + { + return + otherIdentifier.Model == Model && + string.Equals(otherIdentifier.FieldName, FieldName, StringComparison.Ordinal); + } private static void ParseAccessor(Expression> accessor, out object model, out string fieldName) { diff --git a/src/Components/Components/src/Forms/ValidationMessageStore.cs b/src/Components/Components/src/Forms/ValidationMessageStore.cs index 2b520d68df..a8b0664bec 100644 --- a/src/Components/Components/src/Forms/ValidationMessageStore.cs +++ b/src/Components/Components/src/Forms/ValidationMessageStore.cs @@ -33,14 +33,30 @@ namespace Microsoft.AspNetCore.Components.Forms public void Add(in FieldIdentifier fieldIdentifier, string message) => GetOrCreateMessagesListForField(fieldIdentifier).Add(message); + /// + /// Adds a validation message for the specified field. + /// + /// Identifies the field for which to add the message. + /// The validation message. + public void Add(Expression> accessor, string message) + => Add(FieldIdentifier.Create(accessor), message); + /// /// Adds the messages from the specified collection for the specified field. /// /// The identifier for the field. /// The validation messages to be added. - public void AddRange(in FieldIdentifier fieldIdentifier, IEnumerable messages) + public void Add(in FieldIdentifier fieldIdentifier, IEnumerable messages) => GetOrCreateMessagesListForField(fieldIdentifier).AddRange(messages); + /// + /// Adds the messages from the specified collection for the specified field. + /// + /// Identifies the field for which to add the messages. + /// The validation messages to be added. + public void Add(Expression> accessor, IEnumerable messages) + => Add(FieldIdentifier.Create(accessor), messages); + /// /// Gets the validation messages within this for the specified field. /// @@ -74,6 +90,13 @@ namespace Microsoft.AspNetCore.Components.Forms _messages.Clear(); } + /// + /// Removes all messages within this for the specified field. + /// + /// Identifies the field for which to remove the messages. + public void Clear(Expression> accessor) + => Clear(FieldIdentifier.Create(accessor)); + /// /// Removes all messages within this for the specified field. /// diff --git a/src/Components/Components/src/Forms/ValidationMessageStoreExpressionExtensions.cs b/src/Components/Components/src/Forms/ValidationMessageStoreExpressionExtensions.cs deleted file mode 100644 index 6304c6e2c3..0000000000 --- a/src/Components/Components/src/Forms/ValidationMessageStoreExpressionExtensions.cs +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.Linq.Expressions; - -namespace Microsoft.AspNetCore.Components.Forms -{ - /// - /// Provides extension methods to simplify using with expressions. - /// - public static class ValidationMessageStoreExpressionExtensions - { - /// - /// Adds a validation message for the specified field. - /// - /// The . - /// Identifies the field for which to add the message. - /// The validation message. - public static void Add(this ValidationMessageStore store, Expression> accessor, string message) - => store.Add(FieldIdentifier.Create(accessor), message); - - /// - /// Adds the messages from the specified collection for the specified field. - /// - /// The . - /// Identifies the field for which to add the messages. - /// The validation messages to be added. - public static void AddRange(this ValidationMessageStore store, Expression> accessor, IEnumerable messages) - => store.AddRange(FieldIdentifier.Create(accessor), messages); - - /// - /// Removes all messages within this for the specified field. - /// - /// The . - /// Identifies the field for which to remove the messages. - public static void Clear(this ValidationMessageStore store, Expression> accessor) - => store.Clear(FieldIdentifier.Create(accessor)); - } -} diff --git a/src/Components/Components/src/Forms/ValidationRequestedEventArgs.cs b/src/Components/Components/src/Forms/ValidationRequestedEventArgs.cs index cd7f0db2b6..52efde8de5 100644 --- a/src/Components/Components/src/Forms/ValidationRequestedEventArgs.cs +++ b/src/Components/Components/src/Forms/ValidationRequestedEventArgs.cs @@ -1,16 +1,24 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; + namespace Microsoft.AspNetCore.Components.Forms { /// /// Provides information about the event. /// - public sealed class ValidationRequestedEventArgs + public sealed class ValidationRequestedEventArgs : EventArgs { - internal static readonly ValidationRequestedEventArgs Empty = new ValidationRequestedEventArgs(); + /// + /// Gets a shared empty instance of . + /// + public static new readonly ValidationRequestedEventArgs Empty = new ValidationRequestedEventArgs(); - internal ValidationRequestedEventArgs() + /// + /// Creates a new instance of . + /// + public ValidationRequestedEventArgs() { } } diff --git a/src/Components/Components/src/Forms/ValidationStateChangedEventArgs.cs b/src/Components/Components/src/Forms/ValidationStateChangedEventArgs.cs index 0ac4af6658..fd8dbb8d69 100644 --- a/src/Components/Components/src/Forms/ValidationStateChangedEventArgs.cs +++ b/src/Components/Components/src/Forms/ValidationStateChangedEventArgs.cs @@ -1,16 +1,24 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; + namespace Microsoft.AspNetCore.Components.Forms { /// /// Provides information about the event. /// - public sealed class ValidationStateChangedEventArgs + public sealed class ValidationStateChangedEventArgs : EventArgs { - internal static readonly ValidationStateChangedEventArgs Empty = new ValidationStateChangedEventArgs(); + /// + /// Gets a shared empty instance of . + /// + public new static readonly ValidationStateChangedEventArgs Empty = new ValidationStateChangedEventArgs(); - internal ValidationStateChangedEventArgs() + /// + /// Creates a new instance of + /// + public ValidationStateChangedEventArgs() { } } diff --git a/src/Components/Components/test/Forms/ValidationMessageStoreTest.cs b/src/Components/Components/test/Forms/ValidationMessageStoreTest.cs index 75e4ef3452..5264e254bd 100644 --- a/src/Components/Components/test/Forms/ValidationMessageStoreTest.cs +++ b/src/Components/Components/test/Forms/ValidationMessageStoreTest.cs @@ -42,7 +42,7 @@ namespace Microsoft.AspNetCore.Components.Forms } [Fact] - public void CanAddMessagesByRange() + public void CanAddMessagesMultiple() { // Arrange var messages = new ValidationMessageStore(new EditContext(new object())); @@ -50,7 +50,7 @@ namespace Microsoft.AspNetCore.Components.Forms var entries = new[] { "A", "B", "C" }; // Act - messages.AddRange(field1, entries); + messages.Add(field1, entries); // Assert Assert.Equal(entries, messages[field1]); diff --git a/src/Components/Web/ref/Microsoft.AspNetCore.Components.Web.netstandard2.0.cs b/src/Components/Web/ref/Microsoft.AspNetCore.Components.Web.netstandard2.0.cs index f577a47088..c64178d486 100644 --- a/src/Components/Web/ref/Microsoft.AspNetCore.Components.Web.netstandard2.0.cs +++ b/src/Components/Web/ref/Microsoft.AspNetCore.Components.Web.netstandard2.0.cs @@ -276,8 +276,8 @@ namespace Microsoft.AspNetCore.Components.Forms { public static partial class EditContextFieldClassExtensions { - public static string FieldClass(this Microsoft.AspNetCore.Components.Forms.EditContext editContext, in Microsoft.AspNetCore.Components.Forms.FieldIdentifier fieldIdentifier) { throw null; } - public static string FieldClass(this Microsoft.AspNetCore.Components.Forms.EditContext editContext, System.Linq.Expressions.Expression> accessor) { throw null; } + public static string FieldCssClass(this Microsoft.AspNetCore.Components.Forms.EditContext editContext, in Microsoft.AspNetCore.Components.Forms.FieldIdentifier fieldIdentifier) { throw null; } + public static string FieldCssClass(this Microsoft.AspNetCore.Components.Forms.EditContext editContext, System.Linq.Expressions.Expression> accessor) { throw null; } } public partial class EditForm : Microsoft.AspNetCore.Components.ComponentBase { @@ -308,7 +308,6 @@ namespace Microsoft.AspNetCore.Components.Forms protected T CurrentValue { get { throw null; } set { } } protected string CurrentValueAsString { get { throw null; } set { } } protected Microsoft.AspNetCore.Components.Forms.EditContext EditContext { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } - protected string FieldClass { get { throw null; } } protected Microsoft.AspNetCore.Components.Forms.FieldIdentifier FieldIdentifier { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } [Microsoft.AspNetCore.Components.ParameterAttribute] public T Value { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } @@ -372,6 +371,7 @@ namespace Microsoft.AspNetCore.Components.Forms [Microsoft.AspNetCore.Components.ParameterAttribute] public System.Linq.Expressions.Expression> For { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } protected override void BuildRenderTree(Microsoft.AspNetCore.Components.RenderTree.RenderTreeBuilder builder) { } + protected virtual void Dispose(bool disposing) { } protected override void OnParametersSet() { } void System.IDisposable.Dispose() { } } @@ -381,6 +381,7 @@ namespace Microsoft.AspNetCore.Components.Forms [Microsoft.AspNetCore.Components.ParameterAttribute(CaptureUnmatchedValues=true)] public System.Collections.Generic.IReadOnlyDictionary AdditionalAttributes { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } } protected override void BuildRenderTree(Microsoft.AspNetCore.Components.RenderTree.RenderTreeBuilder builder) { } + protected virtual void Dispose(bool disposing) { } protected override void OnParametersSet() { } void System.IDisposable.Dispose() { } } diff --git a/src/Components/Web/src/Forms/EditContextFieldClassExtensions.cs b/src/Components/Web/src/Forms/EditContextFieldClassExtensions.cs index bd92563535..687328043a 100644 --- a/src/Components/Web/src/Forms/EditContextFieldClassExtensions.cs +++ b/src/Components/Web/src/Forms/EditContextFieldClassExtensions.cs @@ -14,23 +14,23 @@ namespace Microsoft.AspNetCore.Components.Forms public static class EditContextFieldClassExtensions { /// - /// Gets a string that indicates the status of the specified field. This will include + /// Gets a string that indicates the status of the specified field as a CSS class. This will include /// some combination of "modified", "valid", or "invalid", depending on the status of the field. /// /// The . /// An identifier for the field. /// A string that indicates the status of the field. - public static string FieldClass(this EditContext editContext, Expression> accessor) - => FieldClass(editContext, FieldIdentifier.Create(accessor)); + public static string FieldCssClass(this EditContext editContext, Expression> accessor) + => FieldCssClass(editContext, FieldIdentifier.Create(accessor)); /// - /// Gets a string that indicates the status of the specified field. This will include + /// Gets a string that indicates the status of the specified field as a CSS class. This will include /// some combination of "modified", "valid", or "invalid", depending on the status of the field. /// /// The . /// An identifier for the field. /// A string that indicates the status of the field. - public static string FieldClass(this EditContext editContext, in FieldIdentifier fieldIdentifier) + public static string FieldCssClass(this EditContext editContext, in FieldIdentifier fieldIdentifier) { var isValid = !editContext.GetValidationMessages(fieldIdentifier).Any(); if (editContext.IsModified(fieldIdentifier)) diff --git a/src/Components/Web/src/Forms/InputBase.cs b/src/Components/Web/src/Forms/InputBase.cs index b103ad0d8b..4202aec396 100644 --- a/src/Components/Web/src/Forms/InputBase.cs +++ b/src/Components/Web/src/Forms/InputBase.cs @@ -143,8 +143,8 @@ namespace Microsoft.AspNetCore.Components.Forms /// Gets a string that indicates the status of the field being edited. This will include /// some combination of "modified", "valid", or "invalid", depending on the status of the field. /// - protected string FieldClass - => EditContext.FieldClass(FieldIdentifier); + private string FieldClass + => EditContext.FieldCssClass(FieldIdentifier); /// /// Gets a CSS class string that combines the class attribute and diff --git a/src/Components/Web/src/Forms/ValidationMessage.cs b/src/Components/Web/src/Forms/ValidationMessage.cs index 6102843f44..f4676d7921 100644 --- a/src/Components/Web/src/Forms/ValidationMessage.cs +++ b/src/Components/Web/src/Forms/ValidationMessage.cs @@ -85,9 +85,14 @@ namespace Microsoft.AspNetCore.Components.Forms StateHasChanged(); } + protected virtual void Dispose(bool disposing) + { + } + void IDisposable.Dispose() { DetachValidationStateChangedListener(); + Dispose(disposing: true); } private void DetachValidationStateChangedListener() diff --git a/src/Components/Web/src/Forms/ValidationSummary.cs b/src/Components/Web/src/Forms/ValidationSummary.cs index dc119a4f36..b0ed6596cd 100644 --- a/src/Components/Web/src/Forms/ValidationSummary.cs +++ b/src/Components/Web/src/Forms/ValidationSummary.cs @@ -82,9 +82,14 @@ namespace Microsoft.AspNetCore.Components.Forms StateHasChanged(); } + protected virtual void Dispose(bool disposing) + { + } + void IDisposable.Dispose() { DetachValidationStateChangedListener(); + Dispose(disposing: true); } private void DetachValidationStateChangedListener() diff --git a/src/Components/Web/test/Forms/InputBaseTest.cs b/src/Components/Web/test/Forms/InputBaseTest.cs index 71deade2b3..8be8525365 100644 --- a/src/Components/Web/test/Forms/InputBaseTest.cs +++ b/src/Components/Web/test/Forms/InputBaseTest.cs @@ -213,28 +213,23 @@ namespace Microsoft.AspNetCore.Components.Forms // Act/Assert: Initally, it's valid and unmodified var inputComponent = await RenderAndGetTestInputComponentAsync(rootComponent); - Assert.Equal("valid", inputComponent.FieldClass); - Assert.Equal("valid", inputComponent.CssClass); // Same because no Class was specified + Assert.Equal("valid", inputComponent.CssClass); // no Class was specified // Act/Assert: Modify the field rootComponent.EditContext.NotifyFieldChanged(fieldIdentifier); - Assert.Equal("modified valid", inputComponent.FieldClass); Assert.Equal("modified valid", inputComponent.CssClass); // Act/Assert: Make it invalid var messages = new ValidationMessageStore(rootComponent.EditContext); messages.Add(fieldIdentifier, "I do not like this value"); - Assert.Equal("modified invalid", inputComponent.FieldClass); Assert.Equal("modified invalid", inputComponent.CssClass); // Act/Assert: Clear the modification flag rootComponent.EditContext.MarkAsUnmodified(fieldIdentifier); - Assert.Equal("invalid", inputComponent.FieldClass); Assert.Equal("invalid", inputComponent.CssClass); // Act/Assert: Make it valid messages.Clear(); - Assert.Equal("valid", inputComponent.FieldClass); Assert.Equal("valid", inputComponent.CssClass); } @@ -256,12 +251,10 @@ namespace Microsoft.AspNetCore.Components.Forms // Act/Assert var inputComponent = await RenderAndGetTestInputComponentAsync(rootComponent); - Assert.Equal("valid", inputComponent.FieldClass); Assert.Equal("my-class other-class valid", inputComponent.CssClass); // Act/Assert: Retains custom class when changing field class rootComponent.EditContext.NotifyFieldChanged(fieldIdentifier); - Assert.Equal("modified valid", inputComponent.FieldClass); Assert.Equal("my-class other-class modified valid", inputComponent.CssClass); } @@ -393,8 +386,6 @@ namespace Microsoft.AspNetCore.Components.Forms public new FieldIdentifier FieldIdentifier => base.FieldIdentifier; - public new string FieldClass => base.FieldClass; - protected override bool TryParseValueFromString(string value, out T result, out string validationErrorMessage) { throw new NotImplementedException(); diff --git a/src/Components/test/testassets/BasicTestApp/FormsTest/NotifyPropertyChangedValidationComponent.razor b/src/Components/test/testassets/BasicTestApp/FormsTest/NotifyPropertyChangedValidationComponent.razor index 8cc8859ad9..1fd89a851f 100644 --- a/src/Components/test/testassets/BasicTestApp/FormsTest/NotifyPropertyChangedValidationComponent.razor +++ b/src/Components/test/testassets/BasicTestApp/FormsTest/NotifyPropertyChangedValidationComponent.razor @@ -18,11 +18,11 @@

User name: - +

Accept terms: - +

diff --git a/src/Components/test/testassets/BasicTestApp/FormsTest/SimpleValidationComponent.razor b/src/Components/test/testassets/BasicTestApp/FormsTest/SimpleValidationComponent.razor index 5182f53a49..aa8ccfbe54 100644 --- a/src/Components/test/testassets/BasicTestApp/FormsTest/SimpleValidationComponent.razor +++ b/src/Components/test/testassets/BasicTestApp/FormsTest/SimpleValidationComponent.razor @@ -5,10 +5,10 @@

- User name: + User name:

- Accept terms: + Accept terms: