@@ -20,6 +20,7 @@ import {
20
20
import { clearFiles , hasFiles } from '../utils/files'
21
21
import { useSanctumClient } from '#imports'
22
22
23
+ // TODO: implement a Nuxt UI compatible version of this composable (via decorator?)
23
24
export const usePrecognitionForm = < T extends Payload > (
24
25
method : RequestMethod ,
25
26
url : string ,
@@ -39,6 +40,7 @@ export const usePrecognitionForm = <T extends Payload>(
39
40
40
41
// TODO: refactor and decompose this function (separate current state and arguments)
41
42
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)
42
44
let payload = form . data ( )
43
45
44
46
const headers = new Headers ( )
@@ -49,9 +51,11 @@ export const usePrecognitionForm = <T extends Payload>(
49
51
headers . set ( CONTENT_TYPE_HEADER , 'multipart/form-data' )
50
52
}
51
53
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
+ }
55
59
}
56
60
}
57
61
0 commit comments