nova-flexible-content
nova-flexible-content copied to clipboard
validation rule images fails.
hi I have the following block
Flexible::make('Content') ->addLayout('Image - One Image', 'image_full', [ Image::make('Image')->rules('image'), ]) ->addLayout('Image - Two Image', 'image_two', [ Image::make('Image 1')->rules('image'), Image::make('Image 2')->rules('image'), ])
If i remove the ->rules('image) it works fine. Otherwise i get the error, "image must be an image" when attmpting to upload an image. Unsure about other field types but the image validation ones are failing
Hi @kevinrevill, I'm a bit puzzled as to why you're using the image rule on an image field. My understanding is that the image field in Nova only lets you pick image files anyway, so this rule seems unnecessary. However if you need a specific file format, you can try using the mimetypes rule.
I use image, in case the user attempts to upload a file which is not an image type, so that it gives an error instead of failing silently. I could use the mimetypes rules of course.
in case the user attempts to upload a file which is not an image type
Doesn't the Image field already prevent this from happening?
It does, but it does not give an error. Just does not upload the file. Again thanks for the help, I will have a look at using the mimetypes.
Same issue here
the code below will show The image must be a file of type: png, jpg, jpeg. for any type of the file
Flexible::make('Additional Resource','additional') ->addLayout('Images','images',[ Image::make('Image', 'image')->rules(['mimes:png,jpg,jpeg'])->path('public/images')->disableDownload() ])
** update** Looks like Nova doesnt handle the validation for the Images field by default
Hi everyone,
I'm closing this issue since it seems to be a more generic Nova-related issue. Please re-open it if you have more information about the Flexible field's role in the problem.
@Nyratas
Hi Nyratas,
Thank you for following up,
The Nova field 'image' doesnt handle the file type check. and you have to use ->rules(['mimes:png,jpg,jpeg']) in order to check the mimes.
but in this case, the rule() function is not working properly in flexiable content, it always return false for any file type
Hi @shindass, thanks for the insight. Re-opening this issue :)
Hi guys ! I have a quite similar issue;Image::make('Image', 'image')->rules('required', 'max:500') seems to validate against the name of the image, not the image itself
Same issue here.
I'm also experiencing this when trying to validate PDF content on the File field - e.g. mimes:pdf and mimetypes:application/pdf. Both of those iterations fail to validate properly within Flexible Content
Laravel 7.28 Nova Flexible Content - dev-master at 80c9266 Nova 3.8.2
I've just opened #237 and #238 which seem to be related to this issue.
Has anyone managed to work around this yet?
I don't know if it will help but in my case, I did the following
- I created a custom validation request
and I put the rule as follows
public function passes($attribute, $value)
{
//Check if file is PDF
return Request::file($value)->getMimeType() === 'application/pdf';
}
I'm experiencing a similar issue with file size validation not working inside of the flexible content field.
Image::rules->('max:1000') does not work to limit the file size to 1000kb/1mb.
A few changes have been released in v1.0.8 thanks to @michaelbaril's PR (#310). Could someone please confirm that all cases covered by this issue have been solved? Thanks.