A few of the node types on my site have a controlling field ( a tickbox) which must be filled in. If the user ticks it, then a controlled field appears. This is a text field and also must be filled in.

Ideally, if the tickbox isn't ticked then I don't want an error message to be displayed due to the controlled field being left blank. This is what happens in two of the four occasions where this sort of setup is implemented on my node types. However, on the other two occasions Drupal complains that I haven't completed the controlled fields, even if they aren't visible.

Am I missing some setting, or is this a bug?

CommentFileSizeAuthor
#4 conditional_fields_453204.patch1.12 KBpeterpoe

Comments

peterpoe’s picture

Could you please export your content type and fields definitions and send them so that I can test?
(We have import/export compatibility now! You have to update to the latest cvs to make import/export work)

jim0203’s picture

Yes:

http://drupalbin.com/9266

The four controlled fields are each called "Please specify". They are controlled by on/off tick boxes: if the box is checked, the field is shown.

Two of the tick boxes are called "other"; the other two start with the word "special". It's the fields that are controlled by fields called "Other" that are always being required, even if they are not visible. Interestingly, these fields are contained with field groups. The other fields, which work as I'd expected, are not contained within field groups.

matteogeco’s picture

What happens to me is:

  • If the controlling and the controlled fields aren't in any group, they don't give error when left empty.
  • If the controlled fields are in a different group from the controlling filed, they don't give error when left empty.
  • If the controlling and the controlled field(s) are in the same group, the form gives error even if the controlled fields are hidden, like what happens to jim0203.
peterpoe’s picture

Component: Miscellaneous » Code
Category: support » bug
Status: Active » Fixed
StatusFileSize
new1.12 KB

There was a wrong variable name on line 609. Patch provided. Also, committed to cvs since it is an easy fix. Thanks!

matteogeco’s picture

Ask for reopening the issue, after applying the patch I have this problem: I got some required fields inside a controlled group and they give error even if they are hidden.

peterpoe’s picture

Status: Fixed » Active

@matteogreco: could you please export the content definitions and add to drupalbin.org so that I can more easily test? Thanks.

matteogeco’s picture

Hi peterpoe, thanks for the "live" support; here is my content type: http://drupalbin.com/9272, the controlling field is field_tipo_art_pn, it controls the group group_det_banc, the required fields are field_conto_corrente and field_num_assegno.

PS: I'm not matteogreco, but matteogeco, from the name of the company I work for. ;-)

matteogeco’s picture

Well done, kid! it seems to me that last dev version solves the problem, for me this issue could be closed.

peterpoe’s picture

Status: Active » Fixed

Ok matteog(r)eco, I'll mark this as fixed. ;)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

leon85321’s picture

Status: Closed (fixed) » Active

Hello,

I have just applied the latest dev version and i am having the same problem here for the required field inside a controlled field group.
I have required fields, FieldA, that is not controlled by anything outside of the field group, FieldGroupA, (well it is supposed to be this way i believe),
That FieldGroupA is controlled by a conditional text select field, ControlFieldA.

When I select any options from ControlFieldA that does not trigger FieldGroupA, it gives me error that FieldA is required but it is invisible due to FieldGroupA is not triggered.

Do you have a fix for this?

Thank you,

Leon

leon85321’s picture

Hello again,

I found a work around is to set a default value for that required field...

But maybe yo have a better way to solve it?

Thank you,

Leon

scottrigby’s picture

Status: Active » Needs work

@peterpoe: I installed the dev version, and i do not get an error when conditionally hidden fields are required. However, if the required field is a select list, the field values are not unset - they're still saved in the node object.

servantleader’s picture

I am using the latest dev version and this is still not working. Required fields are still causing errors of left blank. I have a simple checkbox that as controlling a field group that contains required text fields.

peterpoe’s picture

I have just committed a patch that fixes the issues with required fields reported by @leon85321 and @servantleader. There is still one issue remaining: required controlled fields inside a controlled fieldgroup still give the required error if they are left empty, triggered and the fieldgroup is not.

marc angles’s picture

I still have the issue here.

Using the last dev version.

The controlled fields are file_field, some option doesn't trigger any fiel_field but then the node isn't submitted because of these required fields. You can see in the content-type export here :
http://koumbit.pastebin.com/d12278597

urlisse’s picture

It would appear that conditional fields won't work with some required CCK fields, such as filefield or imagefield.

After some enquiry, I found that the filefield module's hook_validate() implements its own way of checking for the #required property: it appears to be checking against the CCK field's required setting returned by the content_types() function. Because of this, it ignores the work done by the conditional fields module using hook_form_alter() and empty required fields will always fail validation, no matter what conditional field does to the form.

balintbrews’s picture

There is still one issue remaining: required controlled fields inside a controlled fieldgroup still give the required error if they are left empty

Still not working... but it would be great. What do you think? Is there any chance to fix it in the immediate future?

Bilmar’s picture

Yes, I experimented with weight of modules but still experienced the issues mentioned above.
It would be great to be able to have this working with imagefield

cdale’s picture

Did the patch in #4 get reverted? Or is there now another typo which looks identical on line 654?

peterpoe’s picture

#20: could you give more context? Patch in #4 has not been reverted.

peterpoe’s picture

#18 Fixed in dev!

cdale’s picture

Sorry. I misread the code. There is no type. :) I was looking at the wrong place.

peterpoe’s picture

Status: Needs work » Fixed

Ok cdale, this is good because I hate those required fields - when I have to fill them in the first place ;)
So I mark this as fixed, feel free to reopen if the required fields require some more attention.

aaronbauman’s picture

Status: Fixed » Needs work

Still busted for me.
Here's my setup:

conditional_fields-6.x-1.x-dev

controlling field: text, radios widget*
2 allowed values: "Yes" and "No" (in that order).
required

controlled field: text, single line text widget
controlling value: "Yes"
required

* - i also tried "select" and "single checkbox". neither works.

perhaps worth noting: neither field is in a fieldgroup.

Then I noticed that the patch in #4 was NOT applied to dev.
So I patched it.
Still doesn't work.

smscotten’s picture

Busted *again* for me. It really had been fixed.

I reverted to 6.x-1.0-beta2 (2009-06-10) and this problem went away, but the problem was exhibited in both the current 6.x-1.0 (2009-Nov-28) and 6.x-1.x-dev (2009-Dec-06) versions.

igorik’s picture

Hi

I can confirm this bug, my required fields (radios, I think date field too) are not required although it's controlfield is checked, and the node is stored with empty required fields.
Using latest conditional fields module 1.x.
Igor

samkat12’s picture

Conditional field is causing fields to be required even if they were not set up to be required. the situation is that when you place the controlling filed out side group and the cotrolled field in a group, the system does not allow you to save, it produces an error message that fields in group are required. even if the fields have been filled in. However there is no error if the controlled field is not triggered.

[...A..] controlling field out side Group

[...B...] Controlled field in a group. (produces an error message that the fields in the group are required to be filled in even if i have put data into them). Can any one help?

peterpoe’s picture

Status: Needs work » Fixed

Just committed a fix to both 1.x and 2.x dev branches... Hope it will be the last!

Bilmar’s picture

thanks for your hard work peterpoe!

capellic’s picture

I just discovered this module yesterday... and I was having problems with 1.1. Then I found this and it works perfectly... just in the nick of time. Thanks!

samkat12’s picture

6.x-2.x-dev works. my issue #28 is been solved. THANK YOU VERY MUCH FOR THE PROMPT RESPONSE TO THIS ISSUE

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

evanbarter’s picture

Status: Closed (fixed) » Active

Sorry for bumping an old issue, but I was wondering if the latest 2.x-dev (commit #352758) caused a regression here? I've got fields which are being conditionally hidden throwing validation errors.

Here's an export of the pertinent fields in my content type: http://drupalbin.com/14424

webflo’s picture

I have the issue. Tested with 1.x / 2.0 / 2.0-beta1 but there are always validation erorrs.

thx flo

jocken’s picture

Had the same issue but replaced checkboxes and radiobuttons to a list. Worked like a charm.

JThan’s picture

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

I get Validation errors on a required filed which is controlled. It is filled out but still the validationsays it needs to be filled. When I deactivate the controll for that field, the field validates as expected.

Updated to last dev, recreated all fields, testet with and without controll.

Edit: Changing the radio buttons to a List did not change anything.

evanbarter’s picture

Priority: Normal » Critical

Is there any chance we could get a resolution on this? I've taken a look at the commit history back to January and poked around the module but I can't figure out why it's currently broken.

evanbarter’s picture

Priority: Critical » Normal

Whoops! I may have been too hasty in bumping up the priority, sorry. I managed to trace my particular issue back to the Formatted Number (http://drupal.org/project/formatted_number) CCK type. While compatibility with this non-core widget would be appreciated, it certainly doesn't warrant critical priority. Hopefully this helps other people still experiencing difficulties.

BeaPower’s picture

Still doesnt work with dev version...

briand44’s picture

I am using the dev version as well and am still having problems. I have a controlling field that is a select list and when a certain option is selected then the controlled field (which is radio buttons and required) appears. If I don't select the certain option then I get an error that says an illegal choice has been detected. If I change the controlled field to a select list it solves the problem. Is there anyway to fix this for radio buttons?

thekevinday’s picture

What happens is that drupal core does not understand that they need to support radio buttons that have no selected choice.

I have opened a bug report here: http://drupal.org/node/919348

scottrigby’s picture

Status: Active » Fixed

@thekevinday the D7 patch i made from your code in #919348: unset form values, such as radio buttons improperly trigger 'An illegal choice has been detected' passed unit testing (it didn't pass @ first until Damien Tournoud changed the version to 7.x-dev).
I literally used the code exactly as you suggested, because it looked good. And seems to work well for this issue.
see http://drupal.org/node/919348#comment-3746952

In the meantime, I've also made a D6 version of the patch for anyone here who needs it:
http://drupal.org/node/919348#comment-3746858

igorik’s picture

Status: Fixed » Needs review
BeaPower’s picture

Any fix for D6? Seems as if the patch failed...

kbk’s picture

Title: Behaviour of required conditional fields » Validation error produced by empty required conditional fields (radio buttons, checkboxes)

The patch mentioned in #43 worked for me although I can't comment on any further affects it may have on Drupal 6 core. Can anybody here?

inky@inky3d.com’s picture

The patch has also worked for me. Have not come across any other issues from this (yet).

dontgoquietly’s picture

inky3d, did you test this on Drupal 6?

sketman’s picture

Hello!
I have the same validation problem when content taxonomy field controlls the formatted integer number. Problem occurs only with formatted integer, integer seems to work fine.
I am using the latest 6.x-2.x-dev version, but it was the same with 6.x-2.0-beta2 and 6.x-1.1.
Any thoughts please?

drwierdo’s picture

Version: 6.x-2.x-dev » 7.x-3.x-dev

It seems there is this very problem also in the 7.x-dev version of this module...can we have a patch for that??
p.s. am i correct in posting this issue here?? Is it the right place??

peterpoe’s picture

Version: 7.x-3.x-dev » 6.x-2.x-dev

#50 7.x-dev did not support required fields at all until today. Please try the latest dev and open and another issue if you find problem with it.

fastdev’s picture

Version: 6.x-2.x-dev » 6.x-2.0
Component: Code » User interface

Hello,

I have the same problem when a list controls a content taxonomy field. If I select an item in the list which does not trigger the content taxonomy field, I get a validation error.
I use Hierarchical Select as a widget for the content taxonomy field.
Do I need to do anything special to make it work ?

tejaspmehta’s picture

does anyone have solution for this ? If yes please post it.

peterpoe’s picture

Status: Needs review » Fixed

This issue should stay closed because it looks that there is no problem with basic CCK fields when they are required.
- If you have problems with fields/widgets provided by modules other from CCK, search the issue queue for issues with a "Compatibility w/ other modules" component, and if you don't find any, file a new one.
- For problems with Drupal core: sorry I can't help.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.