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

Async Validations #1270

Closed
danbaechtold opened this issue Aug 20, 2020 · 3 comments
Closed

Async Validations #1270

danbaechtold opened this issue Aug 20, 2020 · 3 comments
Labels
Type: Feature ⚙ Request or idea for a new feature.
Milestone

Comments

@danbaechtold
Copy link

Validation with async Validator functions don't work (when e.Status is set asynchroniously):

<Validations @ref="validations" ValidateOnLoad="false" StatusChanged="OnValidationsChanged">
    <Field>
        <FieldLabel>Label</FieldLabel>
        <Validation Validator="@ValidateFunc">
            <TextEdit @bind-Text="@Text">
                <Feedback>
                    <ValidationError>Error</ValidationError>
                </Feedback>
            </TextEdit>
        </Validation>
    </Field>
</Validations>
private async void ValidateFunc(ValidatorEventArgs e)
{
    // e.Status = ValidationStatus.Success; // THIS WORKS

    bool valid = await RemoteValidateFunc(e.Value);
    e.Status = ValidationStatus.Success; // THIS DOESN'T WORK (StatusChanged not fired)

    // validations.ValidateAll(); // WORKAROUND (but invalidates all blank fields)
}

It would be very helpful if this could be supported - or is there another way this should be done?

@stsrki
Copy link
Collaborator

stsrki commented Aug 20, 2020

For this scenario I should probably refactor Validator and convert it to EventCallback instead of plain event. It makes sense as it should be more flexible, especially for this kind of situations.

But since it's probably a larger change, and breaking change I will schedule it for one of next milestones.

@stsrki stsrki added the Type: Feature ⚙ Request or idea for a new feature. label Aug 20, 2020
@stsrki stsrki added this to the Backlog milestone Aug 20, 2020
@CPlusPlus17
Copy link

Is there a workaround? I'm facing multiple problems to get this working:

  • I'm using fluent validations
  • One validation uses a REST endpoint

The HttpClient only work as async, waiting with .Result isn't supported with Blazor.

validations.ValidateAll()

Throws an

Object reference not set to an instance of an object.

at this stage in the code path. So I'm out of solutions for the moment?

@stsrki stsrki modified the milestones: Backlog, 0.9.4 Dec 1, 2020
@stsrki
Copy link
Collaborator

stsrki commented Mar 4, 2021

The first prototype of async validation #1958

@stsrki stsrki mentioned this issue Mar 24, 2021
@stsrki stsrki closed this as completed Mar 24, 2021
@stsrki stsrki moved this to ✔ Done in Development Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature ⚙ Request or idea for a new feature.
Projects
Archived in project
Development

No branches or pull requests

3 participants