-
-
Notifications
You must be signed in to change notification settings - Fork 643
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
Array of object with file and a string field throwing "string field must be defined" message always. #4777
Comments
Hey @mdthansil! 👋🏻 What's the content of |
When I use {
images: [ { title: 'Title 1' }, { title: 'Title 2' }, { title: 'Title 3' } ]
} |
Hi @RomainLanz any updates on this? |
It looks like if should work fine. |
hi @RomainLanz Here is the link to the repository. |
Hey @RomainLanz 👋 Please note that The issue only occurs when we use tags: vine.array(vine.object({ key: vine.string(), value: vine.string() })) functions correctly. However, when we attempt something like this: images: vine.array(vine.object({ file: vine.file({ size: '2mb' }), title: vine.string() })) we receive an error stating that the field must be defined. |
I think this issue was reported earlier as-well (maybe in the Discord). The files and the request body are two different objects and hence when you expect them to be present together than you will have to self define the For example, you can use the import merge from 'deepmerge'
request.validateUsing(validator, {
data: merge(request.all(), request.allFiles())
}) |
Try setting This form is currently submitting as |
This issue has been marked as stale because it has been inactive for more than 21 days. Please reopen if you still need help on this issue |
Just ran into this issue. @thetutlage is correct, you would have to deep merge the request @ThisIsMissEm -- setting the SourceHere is the code @thetutlage may be referencing: core/modules/http/request_validator.ts Lines 81 to 87 in 17798dd
ExampleIf both const data = {
...this.#ctx.request.all(), // { foo: { name: bar }}
...this.#ctx.request.allFiles(), // { foo: { file: MultipartFile }}
} The { foo: { file: MultipartFile }} But we expected: { foo: { name: bar, file: MultipartFile }} |
The bodyparser request toJSON {
id: 'example',
url: '/foo/1/bar/2',
query: null,
body: { title: 'asdf', description: null }, // <--
params: { space: '1', item: '2' },
headers: { host: 'localhost:3333' },
method: 'PUT',
protocol: 'http',
hostname: 'localhost',
ip: '::1',
subdomains: {},
files: { custom: { asdf: [MultipartFile] } } // <--
} With that in mind, could we instead update the code to this? const data = validatorOptions.data || {
...this.#ctx.request.all(),
files: this.#ctx.request.allFiles(), // <-- Files under its own 'file' key
params: this.#ctx.request.params(),
headers: this.#ctx.request.headers(),
cookies: this.#ctx.request.cookiesList(),
} Or possibly implement the deep merge into the |
Deep merging will be implemented, but since it will be a breaking change, this has to wait a little :) |
Package version
Adonis Core Version: 6.14.1, vineJS version: 2.1.0
Describe the bug
Using Adonisjs with inertia + vue(SSR)
Reproduction repo
No response
The text was updated successfully, but these errors were encountered: