Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a80feaf

Browse files
committed
minor #13644 Correct defintion of Range validation messages (jamesisaac)
This PR was merged into the 4.4 branch. Discussion ---------- Correct defintion of Range validation messages The example given in the docs doesn't work since this change in 4.4: symfony/symfony@c5488bc Even if you've written a nice min `minMessage` and `maxMessage`, users will just get the default "This value should be between X and Y." message, because the `notInRange` check gets carried out first, and returns before the individual min/max checks get performed. Commits ------- 92e311e Correct defintion of Range validation messages
2 parents 1ecb852 + 92e311e commit a80feaf

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

reference/constraints/Range.rst

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ you might add the following:
5656
- Range:
5757
min: 120
5858
max: 180
59-
minMessage: You must be at least {{ limit }}cm tall to enter
60-
maxMessage: You cannot be taller than {{ limit }}cm to enter
59+
notInRangeMessage: You must be between {{ min }}cm and {{ max }}cm tall to enter
6160
6261
.. code-block:: xml
6362
@@ -72,8 +71,7 @@ you might add the following:
7271
<constraint name="Range">
7372
<option name="min">120</option>
7473
<option name="max">180</option>
75-
<option name="minMessage">You must be at least {{ limit }}cm tall to enter</option>
76-
<option name="maxMessage">You cannot be taller than {{ limit }}cm to enter</option>
74+
<option name="notInRangeMessage">You must be between {{ min }}cm and {{ max }}cm tall to enter</option>
7775
</constraint>
7876
</property>
7977
</class>
@@ -94,8 +92,7 @@ you might add the following:
9492
$metadata->addPropertyConstraint('height', new Assert\Range([
9593
'min' => 120,
9694
'max' => 180,
97-
'minMessage' => 'You must be at least {{ limit }}cm tall to enter',
98-
'maxMessage' => 'You cannot be taller than {{ limit }}cm to enter',
95+
'notInRangeMessage' => 'You must be between {{ min }}cm and {{ max }}cm tall to enter',
9996
]));
10097
}
10198
}
@@ -350,7 +347,8 @@ maxMessage
350347
**type**: ``string`` **default**: ``This value should be {{ limit }} or less.``
351348

352349
The message that will be shown if the underlying value is more than the
353-
`max`_ option.
350+
`max`_ option, and no `min`_ option has been defined (if both are defined, use
351+
`notInRangeMessage`_).
354352

355353
You can use the following parameters in this message:
356354

@@ -397,7 +395,8 @@ minMessage
397395
**type**: ``string`` **default**: ``This value should be {{ limit }} or more.``
398396

399397
The message that will be shown if the underlying value is less than the
400-
`min`_ option.
398+
`min`_ option, and no `max`_ option has been defined (if both are defined, use
399+
`notInRangeMessage`_).
401400

402401
You can use the following parameters in this message:
403402

0 commit comments

Comments
 (0)