laravel / precognition

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

Multi step wizard #95

Open msirse opened 1 month ago

msirse commented 1 month ago

Laravel Precognition Plugin Version

0.5.8

Laravel Version

11

Plugin

Vue w/ Inertia

Description

Multi step wizard and user validate first step and jump to second step. Then click back and jump back to first step.

If the user has not touched any fields, you cannot validate the same fileds. How can I now than form is alrady validated and skip validation, and jump to second step.

Steps To Reproduce

Step 1

skip validation if the user has not touched any fields and the form has already been validated or validate again....

form.touch(["first_name", "last_name"]).validate({ onSuccess: (response) => { nextStep() }, });

timacdonald commented 1 month ago

We would need to add a setTouched function to allow you to control what fields are currently touched. The touch function is always additive.

form.touch(['name'])

form.touch(['email'])

// name and email are now "touched"
e4se commented 1 week ago

For now, this can be resolved using the following approach before the touch method form.validator().reset()

mreduar commented 4 days ago

For now, this can be resolved using the following approach before the touch method form.validator().reset()

This did not work for me, calling the reset method seems to work the same and the validation is not sent. Could you explain a little better how you made it work? I currently have a bug and this is stopping me.

e4se commented 1 day ago

I forgot about onBeforeValidation hook. Like This:

form.validator().reset();
form.touch([
    'name',
    'description',
]).validate({
    onBeforeValidation: (newRequest) => {
        return true
    },
    onSuccess: () => {
    },
});
mreduar commented 1 day ago

I forgot about onBeforeValidation hook. Like This:

form.validator().reset();
form.touch([
    'name',
    'description',
]).validate({
    onBeforeValidation: (newRequest) => {
        return true
    },
    onSuccess: () => {
    },
});

Thank you so much @e4se ! Works great