Skip to content

[Validator] deprecate the allowEmptyString option #13695

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 24, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions reference/constraints/Length.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ and "50", you might add the following:
* 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",
* allowEmptyString = false
* maxMessage = "Your first name cannot be longer than {{ limit }} characters"
* )
*/
protected $firstName;
Expand All @@ -60,7 +59,6 @@ and "50", you might add the following:
max: 50
minMessage: 'Your first name must be at least {{ limit }} characters long'
maxMessage: 'Your first name cannot be longer than {{ limit }} characters'
allowEmptyString: false

.. code-block:: xml

Expand All @@ -81,7 +79,6 @@ and "50", you might add the following:
<option name="maxMessage">
Your first name cannot be longer than {{ limit }} characters
</option>
<option name="allowEmptyString">false</option>
</constraint>
</property>
</class>
Expand All @@ -104,7 +101,6 @@ and "50", you might add the following:
'max' => 50,
'minMessage' => 'Your first name must be at least {{ limit }} characters long',
'maxMessage' => 'Your first name cannot be longer than {{ limit }} characters',
'allowEmptyString' => false,
]));
}
}
Expand All @@ -119,6 +115,13 @@ allowEmptyString

**type**: ``boolean`` **default**: ``false``

.. deprecated:: 5.2

The ``allowEmptyString`` option is deprecated since Symfony 5.2. If you
want to allow empty strings too, combine the ``Length`` constraint with
the :doc:`Blank constraint </reference/constraints/Blank>` inside the
:doc:`AtLeastOneOf constraint </reference/constraints/AtLeastOneOf>`.

If set to ``true``, empty strings are considered valid (which is the same
behavior as previous Symfony versions). The default ``false`` value considers
empty strings not valid.
Expand Down