0
votes

How to disable the inArray validator of Zend\Element\Select ? I can not remove this standard validator select element.

Edit:

What I'm trying to do is populate a select element so dynamic with ajax. So that way the inArray loses the reference field value.

Does anyone know what is the right way to populate this element with ajax?

2
What is the nature of the Problem with this validator? This simply is a security thing to see if the submitted value is actually within your array of values. That's a good thing. Maybe try to explain what your problem is and we have a better solution for you. Furthermore: accept-rate!Sam
I'm populating the select element with ajax. In other words, dynamically. This generates error when the validator tries to do his job inArray.user1906245

2 Answers

0
votes

It actually does not look like it is possible at this point in time to disable the validator; however, you can override the select element to be able to remove the validator for this specific case:

use Zend\Form\Element\Select;

class MySelect extends Select {
    public function getValidator() {
        return $this->validator;
    }
}

Basically the key issue with the current select element is that if the validator does not exist; it will create it. The other option you have here is to set a validator manually; which you should likely be doing is manually creating an InArrayValidator and populating it with the potential options that would be coming from your AJAX call. In which case you would need to add a setter above.

0
votes

Since version 2.2, Zend Framework provide the ability to disable inArray validator calling:

$element->setDisableInArrayValidator(false);

or passing option to an element:

'disable_inarray_validator' => false