File tree 3 files changed +35
-0
lines changed 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)
195
195
public bool IsModified ( Expression < Func < object > > accessor )
196
196
=> IsModified ( FieldIdentifier . Create ( accessor ) ) ;
197
197
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
+
198
213
/// <summary>
199
214
/// Validates this <see cref="EditContext"/>.
200
215
/// </summary>
Original file line number Diff line number Diff line change 1
1
#nullable enable
2
2
Microsoft.AspNetCore.Components.Forms.EditContext.ShouldUseFieldIdentifiers.get -> bool
3
3
Microsoft.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()
233
233
Assert . Equal ( new [ ] { "Some message" } , editContext . GetValidationMessages ( ) ) ;
234
234
}
235
235
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
+
236
254
[ Fact ]
237
255
public void LookingUpModel_ThatOverridesGetHashCodeAndEquals_Works ( )
238
256
{
You can’t perform that action at this time.
0 commit comments