Repository navigation
Preserve modified state when InputBase parsing fails #68365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -115,18 +115,24 @@ protected string? CurrentValueAsString | |
| { | ||
| _incomingValueBeforeParsing = value; | ||
| _parsingValidationMessages?.Clear(); | ||
| var previousParsingAttemptFailed = _previousParsingAttemptFailed; | ||
| var notifyFieldChangedOnSuccessfulRecovery = false; | ||
|
|
||
| if (_nullableUnderlyingType != null && string.IsNullOrEmpty(value)) | ||
| { | ||
| // Assume if it's a nullable type, null/empty inputs should correspond to default(T) | ||
| // Then all subclasses get nullable support almost automatically (they just have to | ||
| // not reject Nullable<T> based on the type itself). | ||
| _parsingFailed = false; | ||
| notifyFieldChangedOnSuccessfulRecovery = previousParsingAttemptFailed && EqualityComparer<TValue>.Default.Equals(default, Value); | ||
| _previousParsingAttemptFailed = false; | ||
| CurrentValue = default!; | ||
| } | ||
| else if (TryParseValueFromString(value, out var parsedValue, out var validationErrorMessage)) | ||
| { | ||
| _parsingFailed = false; | ||
| notifyFieldChangedOnSuccessfulRecovery = previousParsingAttemptFailed && EqualityComparer<TValue>.Default.Equals(parsedValue, Value); | ||
| _previousParsingAttemptFailed = false; | ||
| CurrentValue = parsedValue!; | ||
| } | ||
| else | ||
|
|
@@ -139,13 +145,19 @@ protected string? CurrentValueAsString | |
| _parsingValidationMessages ??= new ValidationMessageStore(EditContext); | ||
| _parsingValidationMessages.Add(FieldIdentifier, validationErrorMessage); | ||
|
|
||
| // Since we're not writing to CurrentValue, we'll need to notify about modification from here | ||
| EditContext.NotifyFieldChanged(FieldIdentifier); | ||
| // The raw input changed, but the model value did not. Track the user interaction | ||
| // without revalidating the unchanged model value. | ||
| EditContext.MarkAsModified(FieldIdentifier); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we also notify the field when parsing successfully recovers to the same model value? For a The current E2E path enters |
||
| } | ||
| } | ||
|
|
||
| if (notifyFieldChangedOnSuccessfulRecovery) | ||
| { | ||
| EditContext?.NotifyFieldChanged(FieldIdentifier); | ||
| } | ||
|
|
||
| // We can skip the validation notification if we were previously valid and still are | ||
| if (_parsingFailed || _previousParsingAttemptFailed) | ||
| if (_parsingFailed || previousParsingAttemptFailed) | ||
| { | ||
| EditContext?.NotifyValidationStateChanged(); | ||
| _previousParsingAttemptFailed = _parsingFailed; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this helper method is needed?