8000 fix: do not remove files on submit · manchenkoff/nuxt-sanctum-precognition@9223732 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 9223732

Browse files
committed
fix: do not remove files on submit
1 parent 7fecc55 commit 9223732

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/runtime/composables/usePrecognitionForm.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
import { clearFiles, hasFiles } from '../utils/files'
2121
import { useSanctumClient } from '#imports'
2222

23+
// TODO: implement a Nuxt UI compatible version of this composable (via decorator?)
2324
export const usePrecognitionForm = <T extends Payload>(
2425
method: RequestMethod,
2526
url: string,
@@ -39,6 +40,7 @@ export const usePrecognitionForm = <T extends Payload>(
3940

4041
// TODO: refactor and decompose this function (separate current state and arguments)
4142
async function process(params: { precognitive: boolean, fields: PayloadKey<T>[], options?: ValidationOptions } = { precognitive: false, fields: [], options: {} }): Promise<ResponseType> {
43+
// TODO: use object-form-encoder (and test with files attached)
4244
let payload = form.data()
4345

4446
const headers = new Headers()
@@ -49,9 +51,11 @@ export const usePrecognitionForm = <T extends Payload>(
4951
headers.set(CONTENT_TYPE_HEADER, 'multipart/form-data')
5052
}
5153
else {
52-
console.warn('Files were detected in the payload but will not be sent. '
53-
+ 'To include files, set `validateFiles` to `true` in the validation options or module config.')
54-
payload = clearFiles(payload)
54+
if (params.precognitive) {
55+
console.warn('Files were detected in the payload but will not be sent. '
56+
+ 'To include files, set `validateFiles` to `true` in the validation options or module config.')
57+
payload = clearFiles(payload)
58+
}
5559
}
5660
}
5761

0 commit comments

Comments
 (0)
0