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

MultiCheckbox custom message for validation not working #177

Open
chougron opened this issue Sep 6, 2017 · 1 comment
Open

MultiCheckbox custom message for validation not working #177

chougron opened this issue Sep 6, 2017 · 1 comment

Comments

@chougron
Copy link

chougron commented Sep 6, 2017

I have an issue happening only for a MultiCheckbox Element, with ZF 2.4.9.

In my form, I create two elements : a text field and a MultiCheckbox field, with this code :

$this->add(array(
    'name' => 'name',
    'type' => 'Text'
));

$value_options = array(
//...
);

$this->add(array(
    'type' => 'Zend\Form\Element\MultiCheckbox',
    'name' => 'equipments',
    'options' => array(
        'value_options' => $value_options,
    )
));

Then, I had the following filter validators :

$this->add(array(
    'name' => 'name',
    'required' => true,
    'validators' => array(
        array(
            'name' => 'Zend\Validator\NotEmpty',
            'options' => array(
               'messages' => array(
                   \Zend\Validator\NotEmpty::IS_EMPTY => 'Please set a name.',
                )
            )
        ),
    ),
));

$this->add(array(
    'name' => 'equipments',
    'required' => true,
    'validators' => array(
        array(
           'name' => 'Zend\Validator\NotEmpty',
            'options' => array(
                'messages' => array(
                    \Zend\Validator\NotEmpty::IS_EMPTY => 'Please select at least one equipment.',
                )
            )
        )
    ),
));

In the end, if I submit my form with no value in any field, two error messages are displayed : Please set a name, which is the good one for name, but for equipments, the default error message is displaying : Value is required and can't be empty.

There must be a problem somewhere when choosing to display the message.

@weierophinney
Copy link
Member

This repository has been closed and moved to laminas/laminas-form; a new issue has been opened at laminas/laminas-form#11.

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

2 participants