symfony2admingenerator / AvocodeFormExtensionsBundle

(old-legacy) Symfony2 form extensions for Admingenerator project (also working standalone!)
Other
48 stars 31 forks source link

Single_upload => The file could not be found. #154

Closed nicoip closed 9 years ago

nicoip commented 9 years ago

Hello,

I use the singl_upload in my form, but when I want to send in my edit form without adding a file, I get the message : "The file could not be found."

I wish the single upload is optional and no requiered

Have you any idea?

Thank you

Entity :

    /**
     * @Assert\File(
     *     maxSize="3M",
     *     maxSizeMessage = "L'image ne doit pas dépasser 3Mb.",
     *     mimeTypes={"image/png", "image/jpeg", "image/pjpeg"},
     *     mimeTypesMessage = "Les images doivent être au format JPG, GIF ou PNG."
     * )
     * @Vich\UploadableField(mapping="apply1_image", fileNameProperty="lookbook1")
     * @var File $lookbook1File    
     */
    protected $lookbook1File;

    /**
     * @var string
     * @ORM\Column(name="lookbook1", type="string", length=100, nullable=true)
     */
    private $lookbook1;   

YML: 

       lookbook1File:
        label:            Lookbook 1
        formType:         afe_single_upload
        dbType:           string
        addFormOptions:
           required: false 
           deleteable:     lookbook1
           data_class:     Symfony\Component\HttpFoundation\File\File 
           previewImages: true
           previewAsCanvas: true
           previewFilter: thumb_apply1
sescandell commented 9 years ago

Hi @nicoip

Could you please show us the generated form from the Admingen?

Don't you have any specfic configuration in your YAML for the edit action?

I'm also wondering if it is not because of the Assert\File validation constraint. Could you please try to remove it (just to make a test) and see if your issue persist?

Thank you,

nicoip commented 9 years ago

Hi, It works by removing the Assert\File validation constraint. There is no specfic configuration in your YAML for the edit action Thank you,

sescandell commented 9 years ago

Hi @nicoip

"It works by removing the Assert\File validation constraint." So I guess this is an issue out of the single_upload component. You need to find a way to say "this field could be empty, but if it's not, it need to be a file with a maximum size of 3M" (to be sure about that, could you replace the single_upload component by a simple file form type and test?)

If the behavior is the same with the file form type, I think you have several ways to handle constraint:

sescandell commented 9 years ago

Forget the reference, just an error from my side

@nicoip : any news on that issue?

ioleo commented 9 years ago

Isn't that the expected behaviour of @Assert\File? I believe this is not a bug, but symfony's implementation of that assertion.

nicoip commented 9 years ago

@loostro and @sescandell , I also think that it is the behavior of symfony.

ioleo commented 9 years ago

Well, as @sescandell suggested, you can play with validation_groups to turn on/off diffrent assertions. Closeing as this is not a bug on our side.