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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

peterpoe’s picture

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.

drupalnesia’s picture

Version: 6.x-2.0-beta1 » 6.x-2.0-beta2

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'!

manuel.adan’s picture

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.

manuel.adan’s picture

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.

carvalhar’s picture

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

yannickoo’s picture

Status: Active » Needs review
FileSize
515 bytes

@carvalhar can you type print_r($field); on line 989 (after the 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.

roball’s picture

Version: 6.x-2.0-beta2 » 6.x-2.0

This problem is also in the 2.0 final, right?

yannickoo’s picture

Title: Required Fields problem » Support for link, media and user reference fields
FileSize
621 bytes

@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?

yannickoo’s picture

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'];
}
peterpoe’s picture

Title: Support for link, media and user reference fields » Use hook_content_is_empty to determine if a required controlled field is empty.
Status: Needs review » Fixed

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.

kbk’s picture

Version: 6.x-2.0 » 6.x-2.x-dev

Fixed in dev, if I am correct.

roball’s picture

Version: 6.x-2.x-dev » 6.x-2.0

But the selected version is usually the latest release having the bug, not that with the bug fixed.

peterpoe’s picture

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.

kbk’s picture

Status: Fixed » Active

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.

peterpoe’s picture

Node reference fields work fine for me. Can you provide an export of the content type?

xaqrox’s picture

Version: 6.x-2.0 » 6.x-2.x-dev
Status: Active » Needs review
FileSize
537 bytes

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 of hook_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 $item in the call to the hook, but my intuition suggests that conditional_fields_is_empty() should expect a single item to maintain the convention established by hook_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.)

Leo Pitt’s picture

The patch at #16 fixes the issue for me.

roball’s picture

Priority: Normal » Critical
Status: Needs review » Reviewed & tested by the community

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 .

TajinderSingh’s picture

Patch #16 fixes it.
Sometimes it takes a lot of time to trace the culprit.
Please commit it. Thanks

dchatry’s picture

Issue summary: View changes

#16 works for me too, can you commit it ?
It's a pretty big issue for those still using D6...

drenton’s picture

#16 works for me too.

peterpoe’s picture

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