Skip to content
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

[Input] NotifyFieldChanged is called twice for all FluentInputBase derived components #1846

Merged
merged 3 commits into from
Apr 12, 2024

Conversation

vnbaaij
Copy link
Collaborator

@vnbaaij vnbaaij commented Apr 12, 2024

Fix #1830 by adding a check to see if NotifyFieldChanged has already been called.

protected virtual async Task ChangeHandlerAsync(ChangeEventArgs e)
{
    var _notifyCalled = false; //<--👈added
    var isValid = TryParseValueFromString(e.Value?.ToString(), out TValue? result, out var validationErrorMessage);

    if (isValid)
    {
        await SetCurrentValueAsync(result ?? default);
        _notifyCalled = true; //<--👈added
    }
    else
    {
        if (FieldBound && CascadedEditContext != null)
        {
            _parsingValidationMessages ??= new ValidationMessageStore(CascadedEditContext);

            _parsingValidationMessages.Clear();
            _parsingValidationMessages.Add(FieldIdentifier, validationErrorMessage ?? "Unknown parsing error");
        }
    }
    if (FieldBound && !_notifyCalled)  //<--👈changed
    {
        CascadedEditContext?.NotifyFieldChanged(FieldIdentifier);
    }
}

@vnbaaij vnbaaij added this to the v4.6.2 milestone Apr 12, 2024
@vnbaaij vnbaaij requested a review from dvoituron as a code owner April 12, 2024 13:06
@vnbaaij vnbaaij merged commit b57322f into dev Apr 12, 2024
3 of 4 checks passed
@vnbaaij vnbaaij deleted the users/vnbaaij/fix-issue-#1830 branch April 12, 2024 13:23
@vnbaaij vnbaaij modified the milestones: v4.6.2, v4.7.0 Apr 22, 2024
vnbaaij added a commit that referenced this pull request Apr 23, 2024
vnbaaij added a commit that referenced this pull request Apr 29, 2024
@kamazheng
Copy link

Fix #1830 by adding a check to see if NotifyFieldChanged has already been called.

protected virtual async Task ChangeHandlerAsync(ChangeEventArgs e)
{
    var _notifyCalled = false; //<--👈added
    var isValid = TryParseValueFromString(e.Value?.ToString(), out TValue? result, out var validationErrorMessage);

    if (isValid)
    {
        await SetCurrentValueAsync(result ?? default);
        _notifyCalled = true; //<--👈added
    }
    else
    {
        if (FieldBound && CascadedEditContext != null)
        {
            _parsingValidationMessages ??= new ValidationMessageStore(CascadedEditContext);

            _parsingValidationMessages.Clear();
            _parsingValidationMessages.Add(FieldIdentifier, validationErrorMessage ?? "Unknown parsing error");
        }
    }
    if (FieldBound && !_notifyCalled)  //<--👈changed
    {
        CascadedEditContext?.NotifyFieldChanged(FieldIdentifier);
    }
}

Update from 4.6.0 to 4.7.0, the FluentSelect SelectedOptionChanged event triggered for some option twice, some not trigger. Strange.
image

combox

The above video shows when the customized select (derived from FluentSelect) selectedOptionChanged to CNC triggered twice, and the value updated back, but for EDM nothing happening.

@vnbaaij
Copy link
Collaborator Author

vnbaaij commented Apr 30, 2024

@kamazheng that is a whole differnet issue and has nothing to do with this NotifyFiledChanged.
Your issue has been addressed already in #1965

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fix: NotifyFieldChanged is called Twice in FluentInputBase.ChangeHandlerAsync
3 participants