Uh oh!
There was an error while loading. Please reload this page.
AVIF image Forms support and MimeType chaining - #1014
Conversation
dg
commented
May 29, 2023
Tu větu |
Poslal somešte pull request do Forms, v ktorom som pridal možnosť priradiť viacero pravidiel pre MimeType v UploadControl. Momentálne, ak sa použije napríklad Image a Mime validátor, v argumente data-nette-rules sa zachovajú obidva, avšak v argumente accept budú uvedené len hodnoty z posledného MimeType pravidla. Moja úprava zjednocuje validáciu tak, že kombinuje predchádzajúce pravidlá (Image a Mime) a argument accept bude obsahovať správne hodnoty. Verím, že táto zmena prispeje k čistejšiemu kódu bez potreby použitia funkcie array_merge. ->addRule(Form::MIME_TYPE, 'Message', array_merge(
FileUpload::ImageMimeTypes,
self::AUDIO_MIME_TYPES, self::VIDEO_MIME_TYPES, self::FILE_MIME_TYPES
)
);Na ->addRule(Form::Image)
->addRule(Form::MIME_TYPE, null, self::AUDIO_MIME_TYPES)
->addRule(Form::MIME_TYPE, null, self::VIDEO_MIME_TYPES)
->addRule(Form::MIME_TYPE, null, self::FILE_MIME_TYPES);$input = $form->addUpload('file7')
->addRule(Form::Image)
->addRule(Form::MimeType, null, ['image/gif', 'text/html']);Aktuálny výstup <inputtype="file" name="file7" accept="image/gif, text/html" id="frm-file7" data-nette-rules='[{"op":":fileSize","msg":"The size of the uploaded file can be up to 33554432 bytes.","arg":33554432},{"op":":image","msg":"The uploaded file must be image in format JPEG, GIF, PNG, WebP or AVIF."},{"op":":mimeType","msg":"The uploaded file is not in the expected format.","arg":["image/gif","text/html"]}]'>Navrhovaný výstup <inputtype="file" name="file7" accept="image/gif, image/png, image/jpeg, image/webp, image/avif, text/html" id="frm-file7" data-nette-rules='[{"op":":fileSize","msg":"The size of the uploaded file can be up to 33554432 bytes.","arg":33554432},{"op":":mimeType","msg":"The uploaded file is not in the expected format.","arg":["image/gif","image/png","image/jpeg","image/webp","image/avif","text/html"]}]'> |
Added AVIF image support for Forms.
Added ability to chain multiple MimeType validators together and prevent deletion of previously set rules.