Skip to content

Commit 8c07377

Browse files
authored
Fixes Vue w/ Inertia validating reactivity (#49)
1 parent 5a1253c commit 8c07377

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

packages/vue-inertia/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
"node": ">=14"
3131
},
3232
"peerDependencies": {
33-
"@inertiajs/vue3": "^1.0.0"
33+
"@inertiajs/vue3": "^1.0.0",
34+
"vue": "^3.0.0"
3435
},
3536
"dependencies": {
3637
"laravel-precognition": "0.5.1",

packages/vue-inertia/src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Config, NamedInputEvent, RequestMethod, SimpleValidationErrors, toSimpleValidationErrors, ValidationConfig, ValidationErrors, resolveUrl, resolveMethod } from 'laravel-precognition'
22
import { useForm as usePrecognitiveForm, client } from 'laravel-precognition-vue'
33
import { useForm as useInertiaForm } from '@inertiajs/vue3'
4+
import { watchEffect } from 'vue'
45

56
export { client }
67

@@ -143,5 +144,10 @@ export const useForm = <Data extends Record<string, unknown>>(method: RequestMet
143144
validator: precognitiveForm.validator,
144145
})
145146

147+
// Due to the nature of `reactive` elements, reactivity is not inherited by
148+
// the patched Inertia form as we have to destructure the Precog form. We
149+
// can handle this by watching for changes and apply the changes manually.
150+
watchEffect(() => form.validating = precognitiveForm.validating)
151+
146152
return form
147153
}

0 commit comments

Comments
 (0)