Skip to content
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

maxLength is not working when Length annotation is used #39

Open
roberto910907 opened this issue Jun 9, 2019 · 1 comment
Open

maxLength is not working when Length annotation is used #39

roberto910907 opened this issue Jun 9, 2019 · 1 comment

Comments

@roberto910907
Copy link

@nacmartin I've found that the following annotation is not being serialized as expected:

Using the Length annotation from the Symfony's doc, it turns out that minLength is correctly being added but not maxLength.

I noticed that you implemented a new ValidatorGuesser for covering the missing guessMinLength in ValidatorTypeGuesser from the Symfony core.

I also found that you're using your custom class to guess the minLength based on some constraints but you're not doing the same for the other methods, eg: addMaxLength.

So, using something like:

    /**
     * @Assert\NotBlank()
     * @Assert\Length(
     *      min = 2,
     *      max = 50,
     *      minMessage = "Your first name must be at least {{ limit }} characters long",
     *      maxMessage = "Your first name cannot be longer than {{ limit }} characters"
     * )
     *
     * @ORM\Column(type="string", length=50)
     */
    private $name;

we will end up receiving the following json-schema:

name: {type: "string", title: "Name", minLength: 2, propertyOrder: 1}
minLength: 2
propertyOrder: 1
title: "Name"
type: "string"

as you can see the maxLength is missing.

For now, I figured out that I can still fix this by adding the maxLength option attr into my form field configuration but I would definitely wish to rely on my entity constraints.

Is there any way to solve this?

@jrbarnard
Copy link
Contributor

Looking at the StringTransformer it only calls the ValidationGuesser on addingMinlength and relies on the attribute for maxLength, I think a fallback on the addMaxLength method if no attribute set to apply the entity Length constraint as with addMinLength wouldn't be too much work.

For now you could create an extension (docs in the Liform bundle) to do this I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants