Hi all,
I have a form that collects billing and shipping information. I want to be
able to control whether or not the shipping information is required based on
a same as shipping checkbox element. I have written a validator using the
$context array to check whether or not this checkbox is checked. If the
check box is checked, then the element is allowed to be blank. Otherwise,
it is not.
The problem is that the other validators in the chain continue to run when
my custom validator returns true. Since I have other validators that are
needed when the element is not blank this presents a problem.
I considered including custom validators for each element that allowed this
functionality, but then I'd be writing custom validators that would really
only be used once or twice when the basic functionality is reusable.
I was thinking that an flag that allows the validator chain to be broken on
succes would be the best way to address this scenario. Given the following
code from Zend_Form_Element there is no way to break the validator chain
once it starts, as long as the individual validators return isValid = true:
} elseif ($validator->isValid($value, $context)) {
continue;
} else {
$result = false;
if ($this->_hasErrorMessages()) {
$messages = $this->_getErrorMessages();
$errors = $messages;
} else {
$messages = $validator->getMessages();
$errors = array_keys($messages);
}
}
$result = false;
$this->_messages = array_merge($this->_messages, $messages);
$this->_errors = array_merge($this->_errors, $errors);
if ($validator->zfBreakChainOnFailure) {
break;
}
I'm hoping I missed something here and that the group might be able to point
me in the direction of how to handle this Use Case simply
Regards
--
View this message in context:
http://www.nabble.com/validator-break-chain-on-success-tp21296665p21296665.html
Sent from the Zend Framework mailing list archive at Nabble.com.