File tree Expand file tree Collapse file tree 3 files changed +35
-0
lines changed
Expand file tree Collapse file tree 3 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -195,6 +195,21 @@ public bool IsModified(in FieldIdentifier fieldIdentifier)
195195 public bool IsModified ( Expression < Func < object > > accessor )
196196 => IsModified ( FieldIdentifier . Create ( accessor ) ) ;
197197
198+ /// <summary>
199+ /// Determines whether the specified fields in this <see cref="EditContext"/> has no associated validation messages.
200+ /// </summary>
201+ /// <returns>True if the field has no associated validation messages after validation; otherwise false.</returns>
202+ public bool IsValid ( in FieldIdentifier fieldIdentifier )
203+ => ! GetValidationMessages ( fieldIdentifier ) . Any ( ) ;
204+
205+ /// <summary>
206+ /// Determines whether the specified fields in this <see cref="EditContext"/> has no associated validation messages.
207+ /// </summary>
208+ /// <param name="accessor">Identifies the field whose current validation messages should be returned.</param>
209+ /// <returns>True if the field has no associated validation messages after validation; otherwise false.</returns>
210+ public bool IsValid ( Expression < Func < object > > accessor )
211+ => IsValid ( FieldIdentifier . Create ( accessor ) ) ;
212+
198213 /// <summary>
199214 /// Validates this <see cref="EditContext"/>.
200215 /// </summary>
Original file line number Diff line number Diff line change 11#nullable enable
22Microsoft.AspNetCore.Components.Forms.EditContext.ShouldUseFieldIdentifiers.get -> bool
33Microsoft.AspNetCore.Components.Forms.EditContext.ShouldUseFieldIdentifiers.set -> void
4+ Microsoft.AspNetCore.Components.Forms.EditContext.IsValid(in Microsoft.AspNetCore.Components.Forms.FieldIdentifier fieldIdentifier) -> bool
5+ Microsoft.AspNetCore.Components.Forms.EditContext.IsValid(System.Linq.Expressions.Expression<System.Func<object!>!>! accessor) -> bool
Original file line number Diff line number Diff line change @@ -233,6 +233,24 @@ public void RequestsValidationWhenValidateIsCalled()
233233 Assert . Equal ( new [ ] { "Some message" } , editContext . GetValidationMessages ( ) ) ;
234234 }
235235
236+ [ Fact ]
237+ public void IsInvalidWithValidationMessagesForSpecifiedField ( )
238+ {
239+ // Arrange
240+ var editContext = new EditContext ( new object ( ) ) ;
241+ var messages = new ValidationMessageStore ( editContext ) ;
242+ var fieldOnThisModel1 = editContext . Field ( "field1" ) ;
243+ var fieldOnThisModel2 = editContext . Field ( "field2" ) ;
244+ messages . Add (
245+ fieldOnThisModel1 ,
246+ "Some message" ) ;
247+
248+ // Assert
249+ Assert . False ( editContext . Validate ( ) ) ;
250+ Assert . False ( editContext . IsValid ( fieldOnThisModel1 ) ) ;
251+ Assert . True ( editContext . IsValid ( fieldOnThisModel2 ) ) ;
252+ }
253+
236254 [ Fact ]
237255 public void LookingUpModel_ThatOverridesGetHashCodeAndEquals_Works ( )
238256 {
You can’t perform that action at this time.
0 commit comments