Behaviour of required conditional fields

jim0203 - May 4, 2009 - 14:40
Project:Conditional Fields
Version:6.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:fixed
Description

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?

#1

peterpoe - May 10, 2009 - 15:40

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)

#2

jim0203 - May 11, 2009 - 00:20

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.

#3

matteogeco - May 11, 2009 - 09:25

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.

#4

peterpoe - May 11, 2009 - 13:11
Component:Miscellaneous» Code
Category:support request» bug report
Status:active» fixed

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

AttachmentSize
conditional_fields_453204.patch 1.12 KB

#5

matteogeco - May 11, 2009 - 13:40

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.

#6

peterpoe - May 11, 2009 - 13:54
Status:fixed» active

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

#7

matteogeco - May 11, 2009 - 14:18

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. ;-)

#8

matteogeco - June 3, 2009 - 08:50

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

#9

peterpoe - June 9, 2009 - 15:39
Status:active» fixed

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

#10

System Message - June 23, 2009 - 15:40
Status:fixed» closed

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

#11

leon85321 - July 9, 2009 - 18:23
Status:closed» 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

#12

leon85321 - July 9, 2009 - 18:30

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

#13

scottrigby - July 23, 2009 - 18:51
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.

#14

servantleader - August 11, 2009 - 17:02

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.

#15

peterpoe - August 15, 2009 - 22:24

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.

#16

MarcAngles - September 18, 2009 - 15:51

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

#17

urlisse - October 1, 2009 - 03:31

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.

#18

balint.kleri - October 25, 2009 - 16:40

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?

#19

trupal218 - October 27, 2009 - 06:48

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

#20

cdale - November 26, 2009 - 20:23

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

#21

peterpoe - November 28, 2009 - 00:21

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

#22

peterpoe - November 28, 2009 - 01:03

#18 Fixed in dev!

#23

cdale - November 28, 2009 - 07:05

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

#24

peterpoe - November 28, 2009 - 16:14
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.

 
 

Drupal is a registered trademark of Dries Buytaert.