Posted by webadpro on September 30, 2010 at 1:50pm
10 followers
| Project: | Conditional Fields |
| Version: | 6.x-2.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | critical |
| Assigned: | Unassigned |
| Status: | reviewed & tested by the community |
Issue Summary
Hi,
When controlling a field which is required and has unlimited value, all the value fields must be filled in order to validate.
When usually without this module the first value field is required but the second and third are options.
Example:
Telephone *
FIELD 1
FIELD 2
FIELD 3
Only Field 1 is required without Condional Fields module.
When activating a field to control the telephone field all 3 fields becomes required when only 1 should actually be.
Warm regards,
webadpro
Comments
#1
I tested this case in 6.x-2.x-dev and it works as expected: only the first value is required. Please, try to switch to the dev version, or wait for beta2.
#2
On beta2 a non-core CCK Required field fail. My test:
1. Radio Button --> controller
2. Filefield to Upload Photo --> controlled, marked as Required field
Even CF can hide Filefield but when press Submit says: 'Upload Photo is required'!
#3
Hi there,
Just another issue thats might be related to this. My config:
- integer radio field as a controller
- embeded media video field as controlled (required)
no other cck fields. When video (controlled) field is hidden, node form submits right, but when it is shown, I got a required field error message when submit, even when a value is entered in video field.
#4
Embed media field related issue is specific to this type of fields. conditional_fields_check_empty function tries to check empty values on any kind of field, but many of existing field modules have their own empty conditions. Module should use hook_content_is_empty() for this purpose.
Attached patch solves the issue for embed media fields.
#5
hi
i'm having the same kind of issue.
My controlled field is a content taxonomy (with hierarchical select widget), it's required if the controller value is selected.
But even with other value selected, the hidden controlled field is being required, making impossible to save the node.
how should i solve this?
thanks
#6
@carvalhar can you type
<?phpprint_r($field);
?>
function conditional_fields_check_empty($field) {).You should get an array which contains one item. Post a screenshot or just the output please.
I created a new patch which adds support for media embed fields and link fields.
#7
This problem is also in the 2.0 final, right?
#8
@roball, I think so.
I attached a path which contains support for user references fields. Can anybody tell me the key of the value field from content taxonomy? So that we can add them in the patch?
#9
Oh, there is an error with emfield fields because there also has a value key ('embed' => 'http://youtube.com/watch....', 'value' => '').
My quick and dirty check is:
if (isset($field[0]['value']) && empty($field[0]['embed'])) {$value = $field[0]['value'];
}
#10
To my embarrassment I discovered, after years of CCK hacking, that fields usually implement hook_content_is_empty to determine if the field has any value, so I rewrote conditional_fields_check_empty to take advantage of this feature (and renamed it to conditional_fields_is_empty for consistency).
Moreover, I found that some modules, like filefield, use the $form['#field_info'][FIELD_NAME]['required'] property to determine if a field is required, and not $form[FIELD_NAME]['#required'], so I updated conditional_fields_custom_required_field() to take this into account.
The new approach solves the required fields problem with all implementations except those that add extra validation logic ignoring the required property, like the Link module, which is, in my opinion, a bug on their part.
The change is already committed, thanks for the efforts everyone.
#11
Fixed in dev, if I am correct.
#12
But the selected version is usually the latest release having the bug, not that with the bug fixed.
#13
The selected version should be the one to which the patch applies, but I have a bad habit of not waiting for reviews on the patches that I write, so there is no patch here. I think that in this case the right version === undefined.
#14
I've tried out 6.x-2.x-dev (Feb 3, 2012) and there is something wrong. I now have hidden, required node reference fields that halt form submission if they are empty. This should probably be a new issue but the latest dev breaks my form.
#15
Node reference fields work fine for me. Can you provide an export of the content type?
#16
I posted issue #1483994: Calls to hook_content_is_empty should provide single item as first argument., and after much investigation, traced it back to changes introduced by the commit referenced in comment #10 (http://drupalcode.org/project/conditional_fields.git/commit/25e00b9572a0...).
conditional_fields_is_empty()sends the item array to the implementations ofhook_content_is_empty()it finds, but every implementation of that hook (that I could find) expects a single item. My fix was to use$item[0]instead of$itemin the call to the hook, but my intuition suggests thatconditional_fields_is_empty()should expect a single item to maintain the convention established byhook_content_is_empty(). On the other hand, this isn't actually an implementation of that hook, so maybe not.(BTW, following @peterpoe's suggestion "The selected version should be the one to which the patch applies" in #13, I've changed the version to 6.x-2.x-dev.)
#17
The patch at #16 fixes the issue for me.
#18
This issue is really critical because the current 6.x-2.x-dev won't work with required fields (6.x-2.0 did work). Can also confirm that the small and simple patch from #16 solves this issue. Can you please commit? Thanks.
This bug has also been discussed at #1515844: "[fieldname] field is required" error even though I entered data for that field .
#19
Patch #16 fixes it.
Sometimes it takes a lot of time to trace the culprit.
Please commit it. Thanks