-
-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How use Callback validator when field is conditionally required? #2
Comments
hmm there is no feature for this I guess but you can use validationGroup and override isValid method of inputFilter something like this should work(not tested):
Originally posted by @svycka at zendframework/zend-inputfilter#146 (comment) |
Example for you. Use-case, an Entity can have child Entity Coordinates. Coordinates exists out of both latitude and longitude. Coordinates can only exist if both are present and must not be created if only one property is set.
Originally posted by @rkeet at zendframework/zend-inputfilter#146 (comment) |
+1 |
+100 |
Can this be done when using a InputFilterSpecification provided by a Fieldset?
If I add a callback validator to my InputFilterSpecification I can't find a way to access the ValidatorChain, the "$this->getInputs()" function is undefined and I can't see an alternative. |
You can set both fields with 'required' => false and handle them in your Controller when the request is made via POST. Example:
|
@Evair04 |
@froschdesign |
But please use our discussion forum or chat for asking support questions. |
I have two fields and one of them is required if the value of the other is equal to one condition.
How can I do this?
The "campaignFranchise" field is only required when the value of the "campaign" is equal to "franchise".
I try use "continueIfEmpty" and "allowEmpty" but how I don't have value and is required, the validation return false.
https://github.com/zendframework/zend-inputfilter/blob/master/src/Input.php#L410-415
If the field is required false, the validation does not trigger.
https://github.com/zendframework/zend-inputfilter/blob/master/src/BaseInputFilter.php#L251-L256
And if I use the callback validator in "campaign" field, the message error result display in wrong field.
Originally posted by @vincequeiroz at zendframework/zend-inputfilter#146
The text was updated successfully, but these errors were encountered: