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

[5.x] Support Laravel precognition on user forms #8924

Merged

Conversation

ryanmitchell
Copy link
Contributor

@ryanmitchell ryanmitchell commented Nov 3, 2023

This PR adds support for Laravel Precognition to user forms (login, register, profile and password).

Again I've moved the validation logic out of the UserController and into separate FormRequests.

Closes #6950
Closes #7890

@ryanmitchell ryanmitchell changed the title [4.x] Support precognition on user forms [4.x] Support Laravel precognition on user forms Nov 16, 2023
@ryanmitchell ryanmitchell marked this pull request as ready for review December 1, 2023 06:36
@ryanmitchell
Copy link
Contributor Author

@jasonvarga I've updated this now the main PR has merged. It should follow the same principles.

@jasonvarga jasonvarga self-assigned this Jan 30, 2024
@ryanmitchell ryanmitchell changed the title [4.x] Support Laravel precognition on user forms [5.x] Support Laravel precognition on user forms May 10, 2024
The login form is expecting the "default" error bag but we're providing one here so when you submit, no errors will be shown.

Ideally we should change the tag to expect an error bag named user.login but that might be considered a breaking change.
@jasonvarga
Copy link
Member

Just putting these here for the docs. When following our own forms docs for how to set up precognition, it explains we have to add an inner div with the precognition $form. Since the user tags don't have the whole js driver x-data thing, we can't grab the data off the <form> tag.

Instead, we can grab the values from fields.

{{? $values = collect($fields)->mapWithKeys(fn ($field) => [
    $field['handle'] => $field['value']
]) ?}}

<div x-data='{
    form: $form(
        "post",
        $refs.form.getAttribute("action"),
        {{$ $values->toJson() $}}
    ).setErrors({{ error | json }}),
}'>

@jasonvarga jasonvarga merged commit 1211509 into statamic:5.x May 15, 2024
16 checks passed
@ryanmitchell
Copy link
Contributor Author

Thank you ❤️

@ryanmitchell ryanmitchell deleted the feature/precognition-for-user-forms branch May 16, 2024 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants