Can I use Inertia useForm() method with emitting events in Vue3 or is it only for 'get', 'post'... requests? #1141
Unanswered
Ifriqiya
asked this question in
Help (Vue)
Replies: 1 comment 1 reply
-
Was your intention to submit the data in the parent? If so, you can emit the whole form upward into the parent. This approach should work: const form = useForm({});
// ...
emit('messageSent', form) Then with the event for const submit = (form) => {
form.transform((data) => ({
...data,
user: `${user.value.first_name} ${user.value.last_name}`,
})).post('/my/endpoint', {
onSuccess: () => {
// do something here if needed
}
})
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have this child component with a form, where the form inputs are emitted to the parent component. This is code for the child component:
As it is, the 'messageSent' event only sends the 'user' payload and not the 'message' payload. But when I hardcode a message string, the event emits both items.
Before now, I have only used the Inertia form helper methods to make a GET, POST or PATCH request to the backend and I'm wondering if it just doesn't work with events or I'm missing something. Thanks.
Beta Was this translation helpful? Give feedback.
All reactions