Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Element\DateTime construction w/ invalid min / max validation values causes form to not work w/o a clear reason why #158

Closed
jackdpeterson opened this issue Apr 27, 2017 · 1 comment

Comments

@jackdpeterson
Copy link
Contributor

jackdpeterson commented Apr 27, 2017

Given the following array notation, the DateTime Element will indicate that the date information provided on submission is invalid. The cause for this is because the Element is presuming that the min / max validators will ALWAYS construct to a \DateTime object; however, in this case they return to null because the format is not compliant with the expected constant's string.

[
    'spec' => [
        'name' => 'start_time',
        'type' => Zend\Form\Element\DateTime::class,
        'options' => [
            'label' => 'Appointment Date',
        ],
        'attributes' => [
            'min' => '2017-01-01',
            'max' => '2017-12-29',
            'step' => 1,
        ],
    ],
]

The following spec does work:

[
    'spec' => [
        'name' => 'start_time',
        'type' => Zend\Form\Element\DateTime::class,
        'options' => [
            'label' => 'Appointment Date',
        ],
        'attributes' => [
            'min' => '2017-01-01T00:00+00:00',
            'max' => '2017-12-29T23:59+00:00',
            'step' => 1,
        ],
    ],
]
@jackdpeterson
Copy link
Contributor Author

jackdpeterson commented Apr 27, 2017

Stack trace one one gets through submission would look something like this:

#0 vendor\/zendframework\/zend-validator\/src\/ValidatorChain.php(246): Zend\\Validator\\DateStep->isValid('2017-01-01T09:0...', Array)\n
#1 vendor\/zendframework\/zend-inputfilter\/src\/Input.php(434): Zend\\Validator\\ValidatorChain->isValid('2017-01-01T09:0...', Array)\n
#2 vendor\/zendframework\/zend-inputfilter\/src\/BaseInputFilter.php(259): Zend\\InputFilter\\Input->isValid(Array)\n
#3 vendor\/zendframework\/zend-inputfilter\/src\/BaseInputFilter.php(213): Zend\\InputFilter\\BaseInputFilter->validateInputs(Array, Array, NULL)\n
#4 vendor\/zendframework\/zend-inputfilter\/src\/BaseInputFilter.php(237): Zend\\InputFilter\\BaseInputFilter->isValid(NULL)\n
#5 vendor\/zendframework\/zend-inputfilter\/src\/BaseInputFilter.php(213): Zend\\InputFilter\\BaseInputFilter->validateInputs(Array, Array, NULL)\n
#6 vendor\/zendframework\/zend-form\/src\/Form.php(513): Zend\\InputFilter\\BaseInputFilter->isValid()\n

jackdpeterson added a commit to jackdpeterson/zend-form that referenced this issue Apr 27, 2017
Throws an InvalidArgumentException when one attempts to create a DateTime element with a string that does not conform to the expected \DateTime format.
weierophinney added a commit that referenced this issue May 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant