laravel / precognition

Anticipate the outcome of a future HTTP request.
https://laravel.com/docs/precognition
MIT License
132 stars 32 forks source link

onValidate Callback or async validate #56

Closed joncarlson closed 9 months ago

joncarlson commented 10 months ago

Because a validate does a roundtrip to the server, it would be nice to know when that roundtrip is finished.

For example, we have a multi-step form. The fields in each step need to be valid before being able to proceed to the next step.

I would think adding a couple options to the .validate(), similar to the .submit(), would be a great addition, something like:

form.validate(id, { onValidated: function(isValid: boolean) {} })

mreduar commented 10 months ago

This is a very common problem that occurs in wizards and other situations where you need to wait for validation. See https://github.com/laravel/precognition/issues/47#issuecomment-1753201254 https://github.com/laravel/precognition/issues/51

driesvints commented 9 months ago

Thanks @mreduar

joncarlson commented 9 months ago

I see this was closed, but I don't see a resolution for it. Was there a resolution to this? The linked issues are more "hacks" to get around the form not having a validation callback

timacdonald commented 9 months ago

We will be adding this feature. Follow along in https://github.com/laravel/precognition/issues/59

timacdonald commented 2 months ago

Opened for review: https://github.com/laravel/precognition/pull/69

timacdonald commented 1 month ago

Merged and tagged.

<TextInput
    v-model="form.name"
    @change="form.validate('name', {
        onSuccess: () => /* ... */,
        onValidationError: () => /* .. */,
    })"
/>