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] Improve async validation API #109

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

timacdonald
Copy link
Member

@timacdonald timacdonald commented Dec 8, 2024

The API when working with a form wizard is less than ideal. We have done a lot of work recently to make this experience better, but the API never felt right.

You currently need to call the touch method to ensure the current page's inputs are validated - even if the user has not interacted with them.

<button
    onClick={() => form.touch(['name', 'email']).validate({
        onSuccess: () => nextStep(),
    })}
>
    Next Step
</button>

It is also not possible to un-touch an input, which can cause issues with certain form wizard configurations.

This PR intends to make this API better while addressing the issue with not being able to un-touch inputs.

To achieve this we are exposing an only validation key as part of the documented public API. This configuration value already exists, but it is currently called validate and is not intended for public use.

I'm renaming the key to only now that it is public, which makes it a more expected API name in the Laravel ecosystem. I've depreciated validate but kept support for it in case people have been using it.

<button
    onClick={() => form.validate({
        only: ['name', 'email'],
        onSuccess: () => nextStep(),
    })}
>
    Next Step
</button>

When specifying inputs in the only key, validation will only apply to those inputs. Those keys will also be "touched" to ensure their future validation behaviour is expected, including conditional and interdependent validation rules.

@timacdonald
Copy link
Member Author

Docs: laravel/docs#10058

@timacdonald
Copy link
Member Author

Marking this one as draft while I consider how this API naming could conflict with with Inertia's visit options.

@timacdonald timacdonald marked this pull request as draft December 9, 2024 08:26
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.

1 participant