I'm using the money module to handle currency data. A money field consists of a textbox for the numeric value and a select list for choosing the correct currency.
The money module includes the following validation to ensure that a numeric value has been entered when a currency has been selected:
<?php
if (!is_numeric($item['amount']) && $item['currency']) {
$errors[$field['field_name']][$langcode][$delta][] = array(
'error' => 'money_amount',
'message' => t('%name: a valid amount is required when a currency is specified.', array('%name' => $instance['label'])),
);
}
?>
However, when a money field is required, the "currency" part is automatically populated. This means that if a required money field is also an untriggered dependent, the above validation always fails because "currency" is populated but "amount" is not.
Conditional field doesn't seem to remove this field validation error, so the form can't be submitted.
Comment | File | Size | Author |
---|---|---|---|
#4 | conditional_fields-untriggered-dependency-validation-2033209-4.patch | 2.37 KB | morbiD |
#3 | conditional_fields-untriggered-dependency-validation-2033209-2.patch | 2.37 KB | morbiD |
Comments
Comment #1
morbiD CreditAttribution: morbiD commentedAs far as I can tell, this is down to execution order of validation hooks and callbacks.
The order of execution that I'm seeing is:
So money's implemention of
hook_field_validate()
is executing after conditional_fields' validation callback, meaning the callback can't catch the validation error.Not sure what the solution is yet.
Comment #2
morbiD CreditAttribution: morbiD commentedI don't see how this can be fixed within the current system of detecting validation errors in a #element_validate callback and then removing them later in a #validate callback.
The problem is twofold:
Therefore, it seems some detection logic must be added to conditional_fields_form_validate(), rather than just skipping the dependent field when $form_state['conditional_fields_untriggered_dependents'][$index]['errors'] is empty.
Comment #3
morbiD CreditAttribution: morbiD commentedWell, I wrote a patch which attempts to check if there are any validation errors for an untriggered dependency that haven't already been detected by conditional_fields_dependent_validate(), then adds them to the field's array of errors.
I tested very briefly in order to resolve the money field issue I described in the first post, but there could be consequences that I've missed for other use cases.
Comment #4
morbiD CreditAttribution: morbiD commentedLast patch could cause "Invalid argument" PHP errors. Here's a new one.
Comment #4.0
morbiD CreditAttribution: morbiD commentedCorrection
Comment #5
peterpoe CreditAttribution: peterpoe as a volunteer commentedThis was fixed by some other commit.
Comment #7
stefan.kornCould you explain which commit fixed this issue? I am still experiencing this issue with fields that make use of hook_field_validate (i. e. eMail Field or number field) using latest 7.x dev version. So I assume this is not fixed currently?
The patch from #4 is also not working.