nova-flexible-content icon indicating copy to clipboard operation
nova-flexible-content copied to clipboard

validation rule images fails.

Open kevinrevill opened this issue 5 years ago • 15 comments

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

kevinrevill avatar Nov 17 '19 08:11 kevinrevill

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.

voidgraphics avatar Nov 18 '19 09:11 voidgraphics

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.

kevinrevill avatar Nov 18 '19 10:11 kevinrevill

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?

voidgraphics avatar Nov 20 '19 12:11 voidgraphics

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.

kevinrevill avatar Nov 20 '19 12:11 kevinrevill

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

Martent123 avatar Dec 12 '19 16:12 Martent123

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.

toonvandenbos avatar Jan 14 '20 09:01 toonvandenbos

@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

Martent123 avatar Jan 14 '20 15:01 Martent123

Hi @shindass, thanks for the insight. Re-opening this issue :)

toonvandenbos avatar Jan 14 '20 15:01 toonvandenbos

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

vaileamon avatar May 11 '20 16:05 vaileamon

Same issue here.

cgarofalo avatar Jun 04 '20 18:06 cgarofalo

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

mattlibera avatar Sep 11 '20 00:09 mattlibera

I've just opened #237 and #238 which seem to be related to this issue.

Has anyone managed to work around this yet?

mdavis1982 avatar Nov 12 '20 12:11 mdavis1982

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';
}

mateusgalasso avatar Aug 13 '21 18:08 mateusgalasso

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.

jennicar avatar Mar 29 '22 19:03 jennicar

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.

toonvandenbos avatar Jun 27 '23 13:06 toonvandenbos