From ab2c4f1ae0a8ae1eeaa5a7bbb9d431c5e917eb68 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Fri, 1 Feb 2019 10:41:55 +0100 Subject: [PATCH] Document the allowNull option for NotBlank constraint --- reference/constraints/NotBlank.rst | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/reference/constraints/NotBlank.rst b/reference/constraints/NotBlank.rst index 3c030abb927..e4d378c1606 100644 --- a/reference/constraints/NotBlank.rst +++ b/reference/constraints/NotBlank.rst @@ -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 ` | +----------------+------------------------------------------------------------------------+ -| Options | - `message`_ | +| Options | - `allowNull`_ | +| | - `message`_ | | | - `payload`_ | +----------------+------------------------------------------------------------------------+ | Class | :class:`Symfony\\Component\\Validator\\Constraints\\NotBlank` | @@ -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 ~~~~~~~