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

inertia-vue - Use transformed data when validating #70

Closed
gcaraciolo opened this issue Apr 13, 2024 · 1 comment · Fixed by #72
Closed

inertia-vue - Use transformed data when validating #70

gcaraciolo opened this issue Apr 13, 2024 · 1 comment · Fixed by #72
Assignees

Comments

@gcaraciolo
Copy link

gcaraciolo commented Apr 13, 2024

Currently, when the validation is triggered, precognition sends the raw form to be validated. This behaviour conflicts with the transformed data applied when the form is submitted. The problems are:

  • The validation gets wrong data during form validation or submission

My use case to came to this problem was that I need to stringify an array as a single input to avoid php's max_input_vars error in a form-data request.

const form = useForm('post', route('campaigns.store'), {
    messages: [],
    contact_ids: [],
}).transform((data) => ({
      messages: data.messages, // should not be encoded as it has media files in it
      contact_ids: JSON.stringify(data.contact_ids), // must be sent as string to avoid exceeding max_input_vars
  }));
  
function submit() {
    form.submit({ forceFormData: true });
}

When calling form.validate() contact_ids is sent as array, exceeding php's max_input_vars. But when submitting the form, everything works as expected.

I looked over inertiajs and precognition code and the transform is not used in precognition nor exposed from inertiajs to be monkey patched :/.

Do you have any suggestions for this situation? Am I allowed to make a pull request in both inertiajs and precognition with a proposed solution for this?

ps: there's also a question in laracasts forum for the same problem.

@timacdonald
Copy link
Member

I've just opened #72 which will address this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants