Skip to content

[Validator] Add value_length parameter for Length constraint #18201

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

Merged
merged 1 commit into from
May 4, 2023
Merged

[Validator] Add value_length parameter for Length constraint #18201

merged 1 commit into from
May 4, 2023

Conversation

WedgeSama
Copy link
Contributor

@WedgeSama WedgeSama commented Apr 13, 2023

@WedgeSama WedgeSama requested a review from xabbuh as a code owner April 13, 2023 11:51
@carsonbot carsonbot added this to the 6.3 milestone Apr 13, 2023
@OskarStark OskarStark changed the title [Validator] Add value_length to available parameter for Length constraint [Validator] Add value_length parameter for Length constraint Apr 13, 2023
@OskarStark OskarStark added the Waiting Code Merge Docs for features pending to be merged label Apr 13, 2023
@carsonbot carsonbot modified the milestones: 6.3, next Apr 13, 2023
@OskarStark
Copy link
Contributor

Versionadded directive is missing

nicolas-grekas added a commit to symfony/symfony that referenced this pull request Apr 17, 2023
…onstraint (WedgeSama)

This PR was merged into the 6.3 branch.

Discussion
----------

[Validator] Add `value_length` parameter to `Length` constraint

| Q             | A
| ------------- | ---
| Branch?       | 6.3
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       |
| License       | MIT
| Doc PR        | symfony/symfony-docs#18201

Currently, you cannot get the current value length and display it in the error message.
Just add `{{ value_length }}` to transaltion message parameters.

Usage example:
```php
// src/Entity/Participant.php
namespace App\Entity;

use Symfony\Component\Validator\Constraints as Assert;

class Participant
{
    #[Assert\Length(
        min: 2,
        max: 50,
        minMessage: 'Your first name only have {{ value_length }} but it must be at least {{ limit }} characters long',
        maxMessage: 'Your first name cannot be longer than {{ limit }} characters, currently have {{ value_length }}',
    )]
    protected $firstName;
}
```

Commits
-------

a51fa56 [Validator] Add new parameter for translation on Length constraint: current value length.
@javiereguiluz javiereguiluz removed the Waiting Code Merge Docs for features pending to be merged label May 4, 2023
@javiereguiluz
Copy link
Member

Benjamin, thanks for updating the docs ... and congrats on your first Symfony Docs contribution 🎉

@javiereguiluz javiereguiluz merged commit 3702335 into symfony:6.3 May 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants