Issues

ZF-8453: Zend_Dojo_Form_Element_NumberTextBox doesn't allow more than one constraint

Description

It's not possible to use setPattern then subsequently setConstraint on a Zend_Dojo_Form_Element_NumberTextBox.

setPattern uses set constraint to add a pattern as a constraint then setConstraint overwrites the previous setPattern(setConstraint).

Comments

Actually, this is not related to specifically to Zend_Dojo_Form_Element_NumberTextBox but to Zend_Dojo_Form_Element_ValidationTextBox

To describe more closely the issue, a few examples:


$this->addElement(
    'NumberTextBox',
    'number',
    array(
        'label' => 'Number',
        'constraints' => array(
            'places' => '6'
        ),
        'pattern' => '0.######',
        'locale' => 'en'
    )
);

Will generate the the constraints, as expected, for "places", "pattern" and "locale".

But, on the other hand:


$this->addElement(
    'NumberTextBox',
    'number',
    array(
        'label' => 'Number',
        'pattern' => '0.######',
        'locale' => 'en',
        'constraints' => array(
            'places' => '6'
        )
    )
);

will generate constraints only for the "places".

Even if the method name is setConstraints, what it is actually doing is adding constraints, so the second example should generate the same result as the first one.

Patch and tests attached.

Patches reviewed and applied to trunk and 1.11 release branch.

Pull request for porting the patch in ZF2 is sent: https://github.com/zendframework/zf2/pull/272