Validate file uploads in block in Twill 3

Hi there - does anyone know what the correct syntax is to validate file uploads using twillBlockValidationRulesForTranslatedFields? I've got a translated file input for a single pdf.
<x-twill::files name="file" label="Pdf File" :max="1" :translated="true" :required="true" />
<x-twill::files name="file" label="Pdf File" :max="1" :translated="true" :required="true" />
and at the top of the file:
@twillBlockValidationRulesForTranslatedFields([
'file' => 'required|mimes:pdf'
])
@twillBlockValidationRulesForTranslatedFields([
'file' => 'required|mimes:pdf'
])
But on validation this always thinks that the file is missing e.g.
{
"blocks.1063[file][en]": [
"The file field is required."
],
"blocks.en": [
"Failed"
],
"blocks.1063[file][fr]": [
"The file field is required."
],
"blocks.fr": [
"Failed"
]
}
{
"blocks.1063[file][en]": [
"The file field is required."
],
"blocks.en": [
"Failed"
],
"blocks.1063[file][fr]": [
"The file field is required."
],
"blocks.fr": [
"Failed"
]
}
I've tried various other keys for the rule e.g. medias.file etc with similar results. What am I doing wrong? Is this not currently supported?
4 Replies
moussaclarke
moussaclarkeOP2w ago
Medias payload in devtools looks correct as far as I can see:
{
"file[fr]": [
{
"id": 123,
"name": "75b035b4-1a09-4f43-aee3-7228db412713_BP-F2.PDF",
"src": "https://example.com/8843d7f92416211de9ebb963ff4ce28125932878/75b035b4-1a09-4f43-aee3-7228db412713-bp-f2.pdf",
"original": "https://example.com/8843d7f92416211de9ebb963ff4ce28125932878/75b035b4-1a09-4f43-aee3-7228db412713-bfp-f2.pdf",
"size": "1.02 Mb",
"filesizeInMb": "1.02",
"pivot_id": 2614
}
],
"file[en]": [
{
"id": 123,
"name": "75b035b4-1a09-4f43-aee3-7228db412713_BP-F2.PDF",
"src": "https://example.com/8843d7f92416211de9ebb963ff4ce28125932878/75b035b4-1a09-4f43-aee3-7228db412713-bp-f2.pdf",
"original": "https://example.com/8843d7f92416211de9ebb963ff4ce28125932878/75b035b4-1a09-4f43-aee3-7228db412713-bp-f2.pdf",
"size": "1.02 Mb",
"filesizeInMb": "1.02",
"tags": [],
"deleteUrl": null,
"updateUrl": "https://example.test/admin/file-library/files/single-update",
"updateBulkUrl": "https://example.test/dashboard/file-library/files/bulk-update",
"deleteBulkUrl": "https://example.test/dashboard/file-library/files/bulk-delete",
"disabled": false
}
]
}
{
"file[fr]": [
{
"id": 123,
"name": "75b035b4-1a09-4f43-aee3-7228db412713_BP-F2.PDF",
"src": "https://example.com/8843d7f92416211de9ebb963ff4ce28125932878/75b035b4-1a09-4f43-aee3-7228db412713-bp-f2.pdf",
"original": "https://example.com/8843d7f92416211de9ebb963ff4ce28125932878/75b035b4-1a09-4f43-aee3-7228db412713-bfp-f2.pdf",
"size": "1.02 Mb",
"filesizeInMb": "1.02",
"pivot_id": 2614
}
],
"file[en]": [
{
"id": 123,
"name": "75b035b4-1a09-4f43-aee3-7228db412713_BP-F2.PDF",
"src": "https://example.com/8843d7f92416211de9ebb963ff4ce28125932878/75b035b4-1a09-4f43-aee3-7228db412713-bp-f2.pdf",
"original": "https://example.com/8843d7f92416211de9ebb963ff4ce28125932878/75b035b4-1a09-4f43-aee3-7228db412713-bp-f2.pdf",
"size": "1.02 Mb",
"filesizeInMb": "1.02",
"tags": [],
"deleteUrl": null,
"updateUrl": "https://example.test/admin/file-library/files/single-update",
"updateBulkUrl": "https://example.test/dashboard/file-library/files/bulk-update",
"deleteBulkUrl": "https://example.test/dashboard/file-library/files/bulk-delete",
"disabled": false
}
]
}
ifox
ifox2w ago
Hi @moussaclarke there may be a way to make it work but not officially supported. @antonio.a17 recently worked on a PR to improve blocks/repeater validation, but I don't think translated files have been considered specifically.
moussaclarke
moussaclarkeOP2w ago
thanks @ifox I will take a look. is this the pr in question? https://github.com/area17/twill/pull/2638
GitHub
Add support for nested block validation by antonioribeiro · Pull Re...
Description Adds support not only to validate neste blocks, but also for custom messages, all to be set within the block. Here&#39;s how it presents itself: Here&#39;s a full block example...
ifox
ifox2w ago
Correct
Want results from more Discord servers?
Add your server