سؤال

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.

هل كانت مفيدة؟

المحلول

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())
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top