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

MultiCheckbox custom message for validation not working #177

@chougron

Description

@chougron

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.

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