I'm using
- Drupal 6.25
- Conditional Fields 6.x-2.0+10-dev (2012-Feb-02)
- Content Construction Kit (CCK) 6.x-3.x-dev (2012-Jan-12)
I have a content type that works as expected when no fields are triggered conditionally. When I set one field (Course #) to be conditionally triggered by another (Type) then attempt to create a new node in that content type, I receive an error "Course # field is required" even though I have entered a valid string for the course # field. Course # is a required field. If I remove the conditional trigger, no error occurs and the node is created as expected. I found Controlled radio field spits a error even if controlling field is not trigged, but I'm not sure if it's the same problem. Or perhaps I'm misunderstanding how required fields behave with conditional fields? (I'm expecting required fields to be required only if they are visible to the user and specified as required in the field settings in the content type. (The Conditional Fields documentation doesn't seem to explicitly describe how required fields behave.) Nonetheless, I don't understand why I'm receiving an error asking me to complete a field which I had already completed.
Comment | File | Size | Author |
---|---|---|---|
#1 | conditional_fields-cck-validation-errors-1515844-1.patch | 936 bytes | guschilds |
#2 | conditional_fields-cck-validation-errors-1515844-2.patch | 736 bytes | guschilds |
after clicking save.png | 162.42 KB | frankfarm | |
before clicking save.png | 162.07 KB | frankfarm |
Comments
Comment #1
guschilds CreditAttribution: guschilds commentedEdit: Please read this comment, but use the patch in Comment #2. Thanks.
I was experiencing the same problem, both with a textfield and a Date field.
I discovered that it was because conditional_fields_is_empty calls field_module_content_is_empty (field_module being the module that provides the field). It passes $item, which is essentially the field value(s) that is/are being checked. Both text_content_is_empty and date_content_is_empty check whether $item['value'] is empty. In reality, the values exists at $item[0]['value'], $item[1]['value'], and so on. Because nothing exists at $item['value'], it tells conditional_fields_is_empty that the field is empty. At least that is my understanding of the problem.
I have attached a patch that instead loops through the field and passes $item[$key], so that when $item[$key]['value'] is checked, a value is found when one exists. Perhaps this is actually a problem with text.module and date.module, but this was a more reasonable solution for me than altering CCK.
I use a loop for when the field has multiple values allowed. You'll also notice I don't allow it to pass the "Add Another Item" element to the function. I have tested this with single and multiple value CCK text and date fields.
I am happy to hear suggestions to improve my code. Hopefully this helps others and a solution finds itself a part of Conditional Fields.
Gus
Comment #2
guschilds CreditAttribution: guschilds commentedThe patch in Comment #1 includes a Devel function and specific paths. Please use/review the attached. My apologies.
Comment #3
Leo Pitt CreditAttribution: Leo Pitt commentedI'm also experiencing this issue - doing some digging around, this issue looks to be a duplicate of #1483994: Calls to hook_content_is_empty should provide single item as first argument., which in turn links to #927558: Use hook_content_is_empty to determine if a required controlled field is empty..
There's a patch included at the end of the latter comment thread which looks to do the same thing as this patch ... Not sure why it hasn't been incorporated into dev yet.. I'm about to try it out.
Comment #4
guschilds CreditAttribution: guschilds commentedI tested patch #16 in #927558: Use hook_content_is_empty to determine if a required controlled field is empty.. The only situation in which it fails is when multiple values are allowed and the first value isn't filled. This would probably only happen if a user already had multiple values and simply deleted their first. Either way works. Thanks for sharing, I obviously didn't see that.
Not sure if this qualifies as a duplicate so I won't take the liberty of closing this, but someone else can. :)
Comment #5
danimatielo CreditAttribution: danimatielo commentedJust wanted to share that the patch on #2 worked for me too.
Comment #6
rokr CreditAttribution: rokr commentedUh, that bug was a real showstopper for me today. Thanks for patch #2 which is working for me as well. Would be great to see it in -dev.
Comment #7
roball CreditAttribution: roball commentedThis is indeed a duplicate of #927558: Use hook_content_is_empty to determine if a required controlled field is empty. where a simpler and working patch is attached to #16.
Comment #7.0
roball CreditAttribution: roball commentedadded which version of CCK I'm using
Comment #8
SuneSommer CreditAttribution: SuneSommer commentedWhats the status on this, please? I use the latest dev-version, but I am still experiencing this problem...