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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

guschilds’s picture

Edit: 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

guschilds’s picture

Component: Miscellaneous » Compatibility w/ other modules
Status: Active » Needs review
FileSize
736 bytes

The patch in Comment #1 includes a Devel function and specific paths. Please use/review the attached. My apologies.

Leo Pitt’s picture

I'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.

guschilds’s picture

I 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. :)

danimatielo’s picture

Just wanted to share that the patch on #2 worked for me too.

rokr’s picture

Status: Needs review » Reviewed & tested by the community

Uh, 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.

roball’s picture

Status: Reviewed & tested by the community » Closed (duplicate)

This 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.

roball’s picture

Issue summary: View changes

added which version of CCK I'm using

SuneSommer’s picture

Whats the status on this, please? I use the latest dev-version, but I am still experiencing this problem...