Skip to content

Validator with Zend\I18n\Validator\DateTime is always required #7

@weierophinney

Description

@weierophinney

I am attempting to use the DateTime validator in an Apigility project. The configuration is set to not be required and continue if empty, however the validator always returns a validation error.

Input

{"name": "Joe Public", "email": "joe@business.com"}

Validator configuration

1 => array(
    'name' => 'dateField',
    'required' => false,
    'filters' => array(),
    'validators' => array(
        0 => array(
            'name' => 'Zend\\I18n\\Validator\\DateTime',
            'options' => array(
                'pattern' => 'Y-m-d\TH:iP',
                'message' => 'Date format must be Y-m-d\TH:iP',
            ),
        ),
    ),
    'allow_empty' => true,
    'continue_if_empty' => true,
    'description' => 'Date field',
),

Error message

{
  "validation_messages": {
    "dateOfBirth": {
      "datetimeInvalid": "Date format must be Y-m-d\TH:iP"
    }
  },
  "type": "http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html",
  "title": "Unprocessable Entity",
  "status": 422,
  "detail": "Failed Validation"
}

Originally posted by @alexisbmills at zfcampus/zf-content-validation#49

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions