Skip to content

Commit

Permalink
Update validation examples.
Browse files Browse the repository at this point in the history
This method expects the second parameter to be a string error message, while callable is passed at the third parameter.

Original code reference: https://github.com/cakephp/cakephp/blob/master/src/Validation/Validator.php#L850-L866
```  /**
     * Allows a field to be an empty string.
     *
     * This method is equivalent to calling allowEmptyFor() with EMPTY_STRING flag.
     *
     * @param string $field The name of the field.
     * @param string|null $message The message to show if the field is not
     * @param bool|string|callable $when Indicates when the field is allowed to be empty
     * Valid values are true, false, 'create', 'update'. If a callable is passed then
     * the field will allowed to be empty only when the callback returns true.
     * @return $this
     * @see \Cake\Validation\Validator::allowEmptyFor() For detail usage
     */
    public function allowEmptyString(string $field, ?string $message = null, $when = true)
    {
        return $this->allowEmptyFor($field, self::EMPTY_STRING, $when, $message);
    }```
  • Loading branch information
MarwanSalim authored Sep 10, 2020
1 parent cbeccb8 commit 0f7c669
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion en/core-libraries/validation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ accept a callback function as their last argument. If present, the callback
determines whether or not the rule should be applied. For example, a field is
sometimes allowed to be empty::

$validator->allowEmptyString('tax', function ($context) {
$validator->allowEmptyString('tax', 'This field is required', function ($context) {
return !$context['data']['is_taxable'];
});

Expand Down

0 comments on commit 0f7c669

Please sign in to comment.