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

Skip to content

Document the allowNull option for NotBlank constraint #10954

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
Feb 1, 2019
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
24 changes: 16 additions & 8 deletions reference/constraints/NotBlank.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,15 @@ NotBlank
========

Validates that a value is not blank - meaning not equal to a blank string,
a blank array, ``null`` or ``false``::

if (false === $value || (empty($value) && '0' != $value)) {
// validation will fail
}

To force that a value is simply not equal to ``null``, see the
a blank array, ``false`` or ``null`` (null behavior is configurable). To check
that a value is not equal to ``null``, see the
:doc:`/reference/constraints/NotNull` constraint.

+----------------+------------------------------------------------------------------------+
| Applies to | :ref:`property or method <validation-property-target>` |
+----------------+------------------------------------------------------------------------+
| Options | - `message`_ |
| Options | - `allowNull`_ |
| | - `message`_ |
| | - `payload`_ |
+----------------+------------------------------------------------------------------------+
| Class | :class:`Symfony\\Component\\Validator\\Constraints\\NotBlank` |
Expand Down Expand Up @@ -87,6 +83,18 @@ class were not blank, you could do the following:
Options
-------

allowNull
~~~~~~~~~

**type**: ``bool`` **default**: ``false``

If set to ``true``, ``null`` values are considered valid and won't trigger a
constraint violation.

.. versionadded:: 4.3

The ``allowNull`` option was introduced in Symfony 4.3.

message
~~~~~~~

Expand Down