dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.49k stars 10.04k forks source link

Blazor EditContext OnValidationStageChanged for single FieldIdentifiers #44284

Open ljfio opened 2 years ago

ljfio commented 2 years ago

Is there an existing issue for this?

Is your feature request related to a problem? Please describe the problem.

I would like to be able to handle events if the validation state has changed for a single FieldIdentifier

Describe the solution you'd like

It would make most sense to add the FieldIdentifier to the ValidationStateChangedEventArgs that could be set whenever the NotifyValidationStateChanged method on the EditContext is invoked with a FieldIdentifier

The default behaviour could still be an empty event for the whole model but it would be fantastic if you could pass in a range of or an individual FieldIdentifier

In the EditContext:

public void NotifyValidationStateChanged(in FieldIdentifier fieldIdentifier)
{
    OnValidationStateChanged?.Invoke(this, new ValidationStateHasChangedEventArgs(fieldIdentifier));
} 

And the ValidationStateHasChangedEventsArgs being updated to include an additional constructor to take in the FieldIdentifier:

public sealed class ValidationStateHasChangedEventsArgs : EventArgs
{
    // ... existing constructor and static empty instance

    public ValidationStateHasChangedEventArgs(in FieldIdentifier fieldIdentifier)
    {
        FieldIdentifier = fieldIdentifier;
    }

    public FieldIdentifier? FieldIdentifier { get; }
}

Additional context

I believe this will improve performance of handling the OnValidationStateChanged events by allowing components / code that hooks onto these events to filter whether it needs to process this event or not.

In my application I am hooking into the OnFieldChanged and OnValidationRequested to use FluentValidation to update the EditContext with my validation rules then calling the NotifyValidationStateHasChanged. In the instance of just handling field changes, I think it makes sense to notify that validation for that (or dependent fields I am aware of) are only notified of the validation state changed. Across my form I have implemented a custom component that displays my validation message for the component it is associated.

This could also be used to enhance the Microsoft.AspNetCore.Components.Forms.ValidationMessage component by only handling changes when the whole form is updated or just the individual field.

ghost commented 2 years ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

ghost commented 11 months ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.