I have a Select element in my form:
$this->add(array( 'name' => 'cat_id', 'type' => 'Zend\Form\Element\Select', 'options' => array( 'label' => 'Categoria', 'empty_option' => '', 'value_options' => array( '' => '', ), ), ));
value_options populated with database information in my controller ... (is there a better way?)
And I have an InputFilter for it, like this:
$this->add(array( 'name' => 'cat_id', 'required' => true, 'validators' => array( array( 'name' => 'NotEmpty', 'break_chain_on_failure' => true, 'options' => array( 'messages' => array('isEmpty' => 'O campo "Categoria" Γ© obrigatΓ³rio'), ), ), ), ));
Please note that I want to change the message isEmpty ... and what a problem!
When I submit the form, I still get the same message in English:
cat_id: isEmpty : Value is required and can't be empty
So my question is: why do I still have this message? Where did she come from? How can I change it?
Ps: It works well with text elements. Only with Select elements do I get this problem.
Additional question:
If I want to use InArray Validator, for example:
array( 'name' => 'InArray', 'options' => array( 'haystack' => array( ... ), 'messages' => array( 'notInArray' => 'Valor nΓ£o encontrado no banco de dados' ), ), ),
Do I need to always fill haystack fild? This is not to say that the validator should use the value_options form?
Tnks!
EDIT
I'm not sure because no one has confirmed this, but I believe that ZF2 does the default validation with the form element when you set it to type .
For instance,
$this->add(array( 'name' => 'cat_id', 'type' => 'Zend\Form\Element\Select', 'options' => array( 'empty_option' => '', 'value_options' => array(
In this case, ZF2 tries to create some default checks for the Select element, for example, check if it is empty, and check the haystack.
So how can I override the messages in this check?