Add object-level validation APIs to EditContext#67178
Open
VigneshwaranGovindharajan wants to merge 4 commits into
Open
Add object-level validation APIs to EditContext#67178VigneshwaranGovindharajan wants to merge 4 commits into
VigneshwaranGovindharajan wants to merge 4 commits into
Conversation
Contributor
|
Thanks for your PR, @VigneshwaranGovindharajan. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add object-level validation APIs to EditContext
Description
Adds support for querying validation messages and modification state at the model object level in EditContext. This enables consumers to determine validation status for specific nested objects (child models), which is currently not possible using existing APIs.
Today, validation messages can be retrieved either globally or per field, but there is no built-in way to group or filter them by object instance. This makes it difficult to build complex forms (for example, tabbed or sectioned UIs) where validation needs to be associated with a specific sub-model.
This change introduces APIs that allow filtering validation state using the model instance that owns the fields.
Changes:
Added new APIs to EditContext:
IEnumerable GetValidationMessages(object model);
bool IsModified(object model);
void MarkAsUnmodified(object model);
Behavior:
GetValidationMessages(object model) returns all validation messages for fields whose FieldIdentifier.Model matches the provided object.
IsModified(object model) returns true if any field belonging to the specified object has been modified.
MarkAsUnmodified(object model) resets the modified state for all fields of the specified object.
Implementation details:
Iterates over internal _fieldStates and filters entries using: ReferenceEquals(fieldIdentifier.Model, model)
No additional storage or indexing introduced.
Preserves existing validation behavior without changes.
Usage Example
`var errors = editContext.GetValidationMessages(model.Person);
if (errors.Any())
{
// Mark Person section/tab as invalid
}`
Tests
Added unit tests covering:
Fixes #40306