form-manager icon indicating copy to clipboard operation
form-manager copied to clipboard

Use Symfony File constraints

Open nlemoine opened this issue 6 years ago • 3 comments

Hi,

I tried to add a maxSize constraint from Symfony on a file input. Turns out it's not working because Symfony expect a Symfony\Component\HttpFoundation\File\File object.

Is there any way to make file constraints work? If not, that would probably deserves a mention in the docs.

nlemoine avatar Jun 19 '19 15:06 nlemoine

Yep, this is not supported at this moment.

A possible workaround might be adding a Constraint\Callback and create the Symfony File object and file validator in the callback.

Other option (maybe better) could be create a SymfonyFile input, extending the default File class (https://github.com/oscarotero/form-manager/blob/master/src/Inputs/File.php) and modify the setValue method to create and save the Symfony File instance, instead the array data.

oscarotero avatar Jun 20 '19 11:06 oscarotero

Thanks for the fast feedback! I'll try those ways and maybe come back with a PR if I have enough time.

BTW, making a file input required doesn't work either. I add to provide a custom Constraint\Callback for that.

nlemoine avatar Jun 20 '19 13:06 nlemoine