Zend 2-选择元素的默认InArray验证器丢失 [英] Zend 2 - Default InArray Validator of Select Element gets lost

查看:101
本文介绍了Zend 2-选择元素的默认InArray验证器丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Zend 2.2中将过滤器添加到我的选择元素时遇到问题.创建选择元素时,会将默认验证器添加到此元素:

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:

此元素将InArray验证器添加到其输入过滤器规范中,以便在服务器上验证所选值是否属于这些值.

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);

此Zend \ InputFilter \ Input添加到Zend \ InputFilter \ InputFilter,之后又添加到我的表单中.从现在开始,默认的验证程序将丢失.

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.

如何在不丢失其默认验证器的情况下为表单元素添加过滤器?

我错过了什么吗?我不希望这是默认行为,因为每个人都在拼命询问如何停用它.甚至还有一个用于停用它的属性('disable_inarray_validator'),但是,我想保留该验证器,而不必将我的选择框的所有条目传递给我的InputFilter.另外,我在Zend 2文档中没有找到任何内容.我想解决方案一定很简单.预先感谢.

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.

注意:当我将带有InputFilterManager的InputFilter添加到表单时,也会发生同样的情况.

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

推荐答案

请先查看我对您问题的评论.我认为可能没有尝试过的唯一事情就是:

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')

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

这篇关于Zend 2-选择元素的默认InArray验证器丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆