Skip to content

[Form][Validator] Specify attributes of fileType thanks to validatorTypeGuesser #29327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
BorisCharriere opened this issue Nov 26, 2018 · 0 comments

Comments

@BorisCharriere
Copy link

BorisCharriere commented Nov 26, 2018

Description
We could use the property mimeTypes of the Symfony\Component\Validator\Constraints\File to specify the attribute accepted of the field

Example

in Symfony\Component\Form\Extension\Validator\ValidatorTypeGuesser line 125

                if ($constraint->mimeTypes){
                    return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\FileType', array('attr' => ['accept' => implode(', ', $constraint->mimeTypes)]), Guess::HIGH_CONFIDENCE);
                }
                return new TypeGuess('Symfony\Component\Form\Extension\Core\Type\FileType', array(), Guess::HIGH_CONFIDENCE); ```
@BorisCharriere BorisCharriere changed the title Specify attributes of fileType thanks to validatorTypeGuesser [Form] [Validator]Specify attributes of fileType thanks to validatorTypeGuesser Dec 6, 2018
@BorisCharriere BorisCharriere changed the title [Form] [Validator]Specify attributes of fileType thanks to validatorTypeGuesser [Form][Validator] Specify attributes of fileType thanks to validatorTypeGuesser Dec 6, 2018
@fabpot fabpot closed this as completed Mar 4, 2019
@xabbuh xabbuh reopened this Mar 4, 2019
nicolas-grekas added a commit that referenced this issue Jul 24, 2019
…constraint and mime types option (Coosos)

This PR was squashed before being merged into the 4.4 branch (closes #32587).

Discussion
----------

[Form][Validator] Generate accept attribute with file constraint and mime types option

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | yes <!-- please update src/**/CHANGELOG.md files -->
| BC breaks?    | no
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes
| Fixed tickets | #29327
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->

Generate the html `accept` attribute based on the file constraint and mime types option.

Is it necessary to add this feature in the documentation ?

Made with @Timherlaud

_Sorry I have recreated this pull request because I missed my rebase_

Commits
-------

5a7b737 [Form][Validator] Generate accept attribute with file constraint and mime types option
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants