Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MultiCheckbox custom message for validation not working #11

Open
weierophinney opened this issue Dec 31, 2019 · 0 comments
Open

MultiCheckbox custom message for validation not working #11

weierophinney opened this issue Dec 31, 2019 · 0 comments

Comments

@weierophinney
Copy link
Member

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.


Originally posted by @chougron at zendframework/zend-form#177

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant