Well, you can just replace the validator chain with a new one. Let's say I have an element with two validators:
- Zend \ Validator \ NotEmpty
- Zend \ Validator \ EmailAddress
And I want to remove the EmailAddress validator from it. You can do something like this:
// create new validator chain $newValidatorChain = new \Zend\Validator\ValidatorChain; // loop through all validators of the validator chained currently attached to the element foreach ($form->getInputFilter()->get('myElement')->getValidatorChain()->getValidators() as $validator) { // attach validator unless it instance of Zend\Validator\EmailAddress if (!($validator['instance'] instanceof \Zend\Validator\EmailAddress)) { $newValidatorChain->addValidator($validator['instance'], $validator['breakChainOnFailure']); } } // replace the old validator chain on the element $form->getInputFilter()->get('myElement')->setValidatorChain($newValidatorChain);
Just;)
source share