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

5
  • Could you please improved the formatting of your question? Commented Apr 27, 2013 at 5: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())... Commented Apr 27, 2013 at 12:14
  • See the post of Alexander Ermakov (2012-10-15 17:15) here. He's extending the Select class and adding a new method setInarray(...). Don't know iwhether it works, but you could try it out. Commented Apr 27, 2013 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 and Remi Thomas's comment. But for me it's a workaround, not a solution, I would be happy with. Commented Apr 27, 2013 at 14:29
  • thank u : @automatix . your code work . Commented Apr 29, 2013 at 6:12

3 Answers 3

10

Add the disable_inarray_validator to the options:

$this->add(array(
    ...
    'options' => array(
        'disable_inarray_validator' => true,
        'label' => 'county',
    ),
));
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.