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

[0.5.x] Async validate #69

Merged
merged 1 commit into from
Aug 14, 2024
Merged

[0.5.x] Async validate #69

merged 1 commit into from
Aug 14, 2024

Conversation

timacdonald
Copy link
Member

@timacdonald timacdonald commented Apr 12, 2024

This PR introduces the ability to respond to individual validation requests via a callback.

This is the most requested feature of Precognition.

The validate method now accepts a second parameter that can accept configuration.

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

This is also useful when building a wizard. You may call validate without any input name to and progress to the next page on success or show an alert on failure.

<Button 
    @click="form.touch(['name', 'email', 'address', 'phone']).validate({
        onSuccess: () => nextPage(),
        onValidationError: () => notify('You have validation errors'),
    })"
>
    Next
</Button>

The local configuration options will always overwrite the global configuration (or merge intelligently when applicable).

const form = useForm('post', '/register', { ... }, {
    onFinish: () => console.log('global config'),
})

form.validate()
// global config

form.validate({
    onFinish: () => console.log('local config'),
})
// local config

@redwanjamous
Copy link

Hey @timacdonald , thanks for the hard work!
Can you please make sure Inertia is covered in this?
In the original PR (#66 ), react-inertia and vue-inertia packages were not covered.
I tried to cover them in this PR

@timacdonald
Copy link
Member Author

It will cover all packages. Still a WIP.

@djurovicigoor
Copy link

Hello,

Is there any progress on this? It's been almost a month since this has been in Draft. It would be very helpful to have this feature implemented. I have an application in production that isn't working perfectly because I am waiting on this feature.

Thank you.

@timacdonald
Copy link
Member Author

@djurovicigoor, still working on this, just had a few other things that were a higher priority.

This one is back on my list and being pushed forward.

Comment on lines 181 to 195
if (isAxiosError(error) && isCancel(error)) {
throw new RequestCancelled('An in-flight Precognition request was cancelled.', { cause: error })
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we resolve this and then never resolve the latestPromise instead of throwing an error?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if this will fix #73 as well. This seems very much related.

Comment on lines -283 to -285
if (touched.length === 0) {
return
}
Copy link
Member Author

@timacdonald timacdonald May 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now handled in the before callback, which makes better sense to co-locate things.

@valh1996
Copy link

Hi @timacdonald, I just closed my feature request #83 because it seems related.

Do you know when it will be online please?

@timacdonald timacdonald self-assigned this Aug 5, 2024
@timacdonald timacdonald marked this pull request as ready for review August 14, 2024 00:44
@timacdonald timacdonald mentioned this pull request Aug 14, 2024
@taylorotwell taylorotwell merged commit af7b35f into main Aug 14, 2024
2 checks passed
@taylorotwell taylorotwell deleted the async branch August 14, 2024 22:18
@jamesparkes
Copy link

nice work! i've been sitting on this PR for a while. we cannot wait to use it. our team will be leveraging that callback on our app's multistep forms! previously, we'd been 🧀 ing a timeout since the callback didn't exist yet.

@timacdonald timacdonald changed the title [1.x] Async validate [0.5.x] Async validate Aug 15, 2024
@mreduar
Copy link

mreduar commented Aug 22, 2024

Thank you @timacdonald 🙏

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.

8 participants