Zend 2 - Default InArray Validator of Select Element gets lost

天大地大妈咪最大 提交于 2020-01-06 15:10:01

问题


I have an issue when adding a filter to my select elements in Zend 2.2. When creating a select element, a default validator is added to this element:

This element adds an InArray validator to its input filter specification in order to validate on the server if the selected value belongs to the values.

This works fine until I add a custom filter to that element:

$filter = new Input('element_name');
$filter->setRequired(true);
$this->add($filter);

This Zend\InputFilter\Input is added to a Zend\InputFilter\InputFilter which is later added to my form. From now on the default validator is lost.

How can I add a filter to form elements without losing their default validators?

Am I missing something? I don't expect this as the default behaviour, because everyone is desperately asking how to deactivate it. There's even an attribute to deactivate it ('disable_inarray_validator'), however, I want to keep that validator without passing all my entries of the selectbox to my InputFilter. Also I didn't find anything in the Zend 2 documentation. I guess the solution must be something simple. Thanks in advance.

Note: Same happens when I add the InputFilter with the InputFilterManager to the form.


回答1:


Please see my comment on your question first. Only thing I thought might work that I haven't tried to get this to work is:

$input->getFilterChain()
      ->attachByName('stringtrim')

or

$input->getFilterChain()
    ->attach(new StringTrim())


来源:https://stackoverflow.com/questions/21165467/zend-2-default-inarray-validator-of-select-element-gets-lost

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!