Skip to content

[Form] max option of Length Constraint has no effect #11527

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
kl3ryk opened this issue Jul 31, 2014 · 3 comments
Closed

[Form] max option of Length Constraint has no effect #11527

kl3ryk opened this issue Jul 31, 2014 · 3 comments

Comments

@kl3ryk
Copy link

kl3ryk commented Jul 31, 2014

I have the following entity property:

    /**
     * @var string
     *
     * @ORM\Column(name="headline", type="string", length=128)
     * @Assert\NotBlank()
     * @Assert\Length(min="5", max="128")
     */
    private $headline;

form component generate the following html:

<input type="text" id="xxx_headline" name="xxx[headline]" required="required" pattern=".{5,}">

I suppose the fix should be done here: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Form/Extension/Validator/ValidatorTypeGuesser.php#L223

There also could be added maxlength html option.

@Cydonia7
Copy link
Contributor

Cydonia7 commented Aug 1, 2014

Well, in ValidatorTypeGuesser, the lines from 191 to 195 should add the maxlength attribute you are talking about. I don't really know why you are not getting it...

@kl3ryk
Copy link
Author

kl3ryk commented Aug 1, 2014

Ok i have tested it and with the following entity properites

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

    /**
     * @var string

     * @ORM\Column(name="headline", type="string", length=128)
     * @Assert\NotBlank()
     * @Assert\Length(min="5", max="128")
     */
    private $headline;

form component generate the following html:

<input type="text" id="x_position" name="x[position]" maxlength="128">
<input type="text" id="x_headline" name="x[headline]" required="required" pattern=".{5,}">

So i suppose that maxlength attributte is added only when ORM\Column have length property defined widthut any constraint.

@kl3ryk
Copy link
Author

kl3ryk commented Aug 1, 2014

I have also tested $position with the following constraint:

    /**
     * @var string
     *
     * @ORM\Column(name="position", type="string", length=128, nullable=true)
     * @Assert\Length(max="128")
     */
    private $position;

and result is still

<input type="text" id="x_position" name="x[position]" maxlength="128">

So if I will use both min and max properties - maxlength is missing and pattern has only bottom limit defined.

@kl3ryk kl3ryk closed this as completed Aug 1, 2014
@kl3ryk kl3ryk reopened this Aug 1, 2014
@stof stof added Form labels Aug 18, 2014
@webmozart webmozart added Bug and removed Enhancement Good first issue Ideal for your first contribution! (some Symfony experience may be required) labels Oct 20, 2014
fabpot added a commit that referenced this issue Dec 12, 2014
This PR was squashed before being merged into the 2.5 branch (closes #12548).

Discussion
----------

[Form] fixed a maxlength overring on a guessing

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #11527
| License       | MIT
| Doc PR        | -

Commits
-------

7248680 [Form] fixed a maxlength overring on a guessing
@fabpot fabpot closed this as completed Dec 12, 2014
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

5 participants