4

i use this in my Form:

$this->add(array(     
    'type' => 'Zend\Form\Element\Select',       
    'name' => 'county',
    'registerInArrayValidator' => false,
    'attributes' =>  array(
        'id' => 'county',                
        'options' => array(
            //'null'=>'[Select county]',
        ),
    ),
    'options' => array(
        'label' => 'county',
    ),
));

and set value county field with js. after validation, i get error : haystack option is mandatory

Aydin Hassan
  • 1,465
  • 2
  • 20
  • 41
Mohammad Mehdi Habibi
  • 1,601
  • 1
  • 14
  • 30
  • Could you please improved the formatting of your question? – 5ervant - techintel.github.io Apr 27 '13 at 05:10
  • I'm not sure, but I think `registerInArrayValidator` only works for the ZF1. I would formulate the question a some abstractlier: How to remove a validator from the Form Element `ValidatorChain`? Have been debugging a bit and can actually not find and way to do this. Maybe somehow over the `ValidatorPluginManager` (`$form->getInputFilter()->get('myElement')->getValidatorChain()>getPluginManager()`)... – automatix Apr 27 '13 at 12:14
  • See the post of Alexander Ermakov (2012-10-15 17:15) [here](http://zend-framework-community.634137.n4.nabble.com/The-input-was-not-found-in-the-haystack-td4657596.html). He's extending the `Select` class and adding a new method `setInarray(...)`. Don't know iwhether it works, but you could try it out. – automatix Apr 27 '13 at 12:52
  • 1
    This can help you: `$formInputFilter = $form->getInputFilter(); $formInputFilter->remove('county'); $formInputFilter->add((new Zend\InputFilter\Factory())->createInput(array( 'name' => 'county', 'required' => true, )));` See my [question](http://stackoverflow.com/q/16252520/2019043) and Remi Thomas's [comment](http://stackoverflow.com/questions/16252520/how-to-remove-a-validator-from-a-form-element-form-element-validatorchain-in-z?noredirect=1#comment23254235_16252520). But for me it's a workaround, not a solution, I would be happy with. – automatix Apr 27 '13 at 14:29
  • thank u : @automatix . your code work . – Mohammad Mehdi Habibi Apr 29 '13 at 06:12

3 Answers3

10

Add the disable_inarray_validator to the options:

$this->add(array(
    ...
    'options' => array(
        'disable_inarray_validator' => true,
        'label' => 'county',
    ),
));
Mohsen Reza
  • 101
  • 5
2

In https://github.com/zendframework/zf2/blob/master/library/Zend/Form/Element/Select.php there is an option $disableInArrayValidator = false; and the corresponding method here

MadeOfSport
  • 513
  • 1
  • 7
  • 19
0

In ZF1, this is what works:

// using the element instance:
$element->setRegisterInArrayValidator(false);

// or a configuration key as part of the options array:
'registerInArrayValidator' => false

// or
element.options.registerInArrayValidator = false
WebTigers
  • 297
  • 2
  • 8