Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I have a checkbox that controls the visibility of a required field. That is, when the checkbox isn't set, the select list is required.
When checking the checkbox, the select list is made invisible by Conditional Fields, but upon submit Drupal complains that the hidden field is required.
Is Conditional FIelds able to override the required check when hiding or disabling a field?
Comment | File | Size | Author |
---|---|---|---|
#19 | help_dependencies.jpg | 331.16 KB | emcniece |
#13 | 1212752-conditional_fields-required-select.patch | 1.13 KB | mrfelton |
#12 | 1212752-conditional_fields-required-select.patch | 1.13 KB | mrfelton |
#4 | overriding_required_property2.png | 23.21 KB | AtomicTangerine |
Comments
Comment #1
AtomicTangerine CreditAttribution: AtomicTangerine commentedHello there, I've been reading through similar past issues in Conditional Fields, seems as though this is the only thread for this issue ("required" property of control fields for a d7 version).
According to this comment: http://drupal.org/node/453204#comment-4439084 from peterpoe (developer for Conditional Fields), it was only just added in May for the d7 dev, but as for the couple tests I've done, I don't see this functionality at all. I have my dependent and dependee both inside the same field group (so that's not the issue), with the select list (currently required) dependent on a certain box being checked. I would like that required property overridden as the dependency condition is made true (checking a box). Right now, the select list is being hidden, but since the field is required, it complains about not completing a required field. Also, my use case is that the box is asking if a seizure occurred, then the required select list is which staff member responded to the incident.
The thread above, that I linked to, describes the long process of getting all this worked out with d7, including in and around field groups.
If there is a way to override this required property, and I'm just not seeing it, anyone feel free to share what you know. There are a lot of config options for dependencies, and I admit I haven't tried every one to see what happens.
I'm working off the July 1st 7.x-3.x-dev version
Comment #2
MrHaroldA CreditAttribution: MrHaroldA commented@AtomicTangerine: it seems the functionality should be there, according to the comment by Peterpoe... Weird...
Comment #3
AtomicTangerine CreditAttribution: AtomicTangerine commentedPull up a chair....
Ok, after playing around with different scenarios between 2 checkbox fields (both defined by allowed values when creating field), I had success with my situation, and sort of with yours too (there's a workaround, if that's the correct term).
So, I was using 2 checkbox fields like I said, but there was some bug with the dependent's label not showing up. I applied patch: http://drupal.org/node/1215826#comment-4721866 which fixed the checkboxes/radios label issue. I know your dependent field was/is a select list, but I at least thought that the label might have been disappearing because of something related to an attempt at overriding the required property. Turns out they were separate (I think...). But I'm glad for that patch because I was pretty disheartened when I saw two bugs :(
Others, this is zher special case and probably doesn't apply to you....see below for @everyone else
BUT for MrHaroldA's SPECIFIC CASE (capped so people don't get confused and run off) I set up a dependency like so:
dependent: field_a dependee: field_b field_a is visible when field_b has value, at least one of the values 1, 2
Stay with me here MrHaroldA, test it for yourself if you need to or can. This "at least" is an option when you select the Value on the Conditions list. 1 and 2 are the keys for the other items on my list(0='Yes', 1='No', 2='idk' is my list). On the rendered behavior section, I have the first 2 boxes checked because the dependency will be active for all values BUT that one box, and when other boxes are checked, you wanted the dependent field rendered (allow 'required' property), and not rendered when we aren't selecting our "any values". Make sense? So basically, you're doing an inverse dependency. This is a workaround until we get AND/OR support which won't be for a while yet.
So, now you have all your values specified, EXCEPT for that box that will by proxy "do" something, in your "any values". I know I'm probably being really confusing, so I'll do another rephrase to solidify what I've done. Assigning the visible and rendered dependency to every box but one, allows for your special case of wanting to do the exact opposite (check a box to UNrender a field)
@ EVERYONE ELSE: back to everyone else who would read this thread haha. Back to my "playing around", with pretty much every combination of enabled, disabled, rendered, unrendered, visible, etc etc dependencies, that I could think of a use case for, I realized that I was using "Value" for the Condition, which allows for the field to be unrendered until the dependency was met. Voila!!! THIS is how you override 'require', by not rendering the field at all.
As far as I know, this works for single on/off boxes controlling required fields, I only tested that a little, but I haven't found anything wrong yet!!!
Extra for those who aren't picking it up: choose "Value", not "Checked", and the "Value" is you either putting in the key(s) or checking a box yourself, so as to say, THIS is my value. :) (and making sure the first box in rendered behavior is checked, to hide a field when the dependency is activated). It's talking about not rendering the field in the form, which is what we want with this overriding 'require' business.
I know this was long but if you actually read it thank you thank you!! And if you already figured these little details out, good for you, I guess I beat you to letting others know about this semi-confusing but awesome assortment of options.
(btw in case you couldn't tell, peterpoe, your module is great and definitely the most organized issue queue I've ever seen, I love it)
Changed to UI feature request because I think that that rendered behavior list should be available for other choices on the Conditions list. Was there a reason it was restricted to "Value" only?
Comment #4
AtomicTangerine CreditAttribution: AtomicTangerine commentedForgot a screenshot for MrHaroldA's case. I'm such a person, that knows that sometimes it takes a while to understand things. So I tend to overexplain, basically in the hopes that that one person out there who's like me, gets a lightbulb moment when someone takes the time to explain and show something :)
(sorry for all the long-winded-ness)
Comment #5
MrHaroldA CreditAttribution: MrHaroldA commented@AtomicTangerine: Wow, thanx for the elaborate answer! Although I didn't have success with it ;)
This is my form:
When 'External' is checked, the list of organisations (required) should disappear and of course shouldn't cause any errors upon submitting the form.
The only way to get a checkbox is to use a binary field and then Conditional Fields can't use the 'Value' setting with a set of values like you did...
Comment #6
AtomicTangerine CreditAttribution: AtomicTangerine commentedBinary field....? Do you mean a single on/off box? I believe you just don't check the box. Remember, for your very strange case, you want an inverse relationship practically. Showing something when another thing has not happened. Also, if your "binary field" does need keys in 'Value', the keys I had for my list will be different than yours, you define the keys for on/off when you make the field, I can't help you if you don't know the keys to your own data. And no, you can use checkboxes with List(text)/List(integer), List (from the Select or Other module), simply by having something like Yes and No as your options, simple form reorganization.
I was trying to help but getting an answer back of "it doesn't work" doesn't help me to help you, so I find it difficult to reply with anything helpful.
Possible information to provide when you ask people questions, would be describing how something didn't work, or your ideas about it. Hopefully you did research before submitting an issue, so links to comments you found helpful, so your potential answerer has more resources for ideas.
Just suggestions.
Comment #7
MrHaroldA CreditAttribution: MrHaroldA commented@AtomicTangerine,
My sincere apologies if my answer came across as incomplete and/or ignorant. English isn't my native tongue so sometimes I have a hard time expressing myself. I thought adding the form should make all things clear so I didn't bother to write a lot of information down in that reply. Hope this one will clarify things. I really do appreciate your help!!!
I can't get Fields to display a checkbox when using anything other than the binary field. All other attempts ended in displaying a radio field instead of a checkbox. The binary checkbox does have keys/values, but Conditional Fields doesn't allow me to specify a value, only if it's checked or not.
Using a checkbox to control the visibility of a required select list in D6 never was a problem, so I guess my case isn't as strange as it seems...
Thanks again!
Harold
Comment #8
askibinski CreditAttribution: askibinski commentedI've got exactly the same problem. To recreate it is simple and not at all an edge case:
In a content-type:
A. create an on/off checkbox (binary)
B. create another field which is required.
Now, create a dependency like this:
When A is checked, hide (set invisible) field B.
This will work, but give an error because the field which was hidden is required.
Desired behaviour: unset any requirements for fields which are hidden/disabled by conditions. I believe this was the way it worked in D6.
In other words: the checkbox should also be able to toggle the requirement in this case. (this could be a handy action for other scenario's too)
Comment #9
peterpoe CreditAttribution: peterpoe commentedThis issue is actually two issues:
1) Configuration of checkboxes: "Checked/Unchecked" or "Value"?
#5 and #8: The solution to your problem was actually hidden in AtomicTangerine's extensive comment #3:
The "Checked" and "Unchecked" conditions (like all conditions except "Value") are just presentational: all they do is applying the state using basic States API. If you want to have any of the more advanced functionality of Conditional Fields (like conditionally required fields, entity render logic, etc.) you must use the "Value" condition. This makes sense, because if no value is inserted, CF has no means to know whether the dependency is activated or not.
So, if you want a field to SHOW when a checkbox is CHECKED, select "Value" as Condition, "Insert values from widget..." as Value, and check the box underneath "Insert the value that will trigger the dependency."
If you want a field to HIDE when a checkbox is CHECKED, same settings apply except that you have to leave the box from the widget unchecked.
That said, I understand that with checkboxes in particular this can be confusing, since after all there is only one "Value" involved. I will make it clear in the documentation when I'll get to write it and think ways to avoid confusion in the dependency edit page as well.
2) Single on/off checkbox not working
While investigating 1), I found that single on/off checkboxes behaved quite erratically. I have just committed a fix that should make everything work as expected.
Comment #10
AtomicTangerine CreditAttribution: AtomicTangerine commentedThanks so much peterpoe! I knew I wasn't crazy :P
Your work is very much appreciated
Comment #11
mrfelton CreditAttribution: mrfelton commentedPerhaps this works ok for checkboxes now, but it doesn't work for select elements.
DEPENDEE FIELD SETTINGS
Type: Optional select with 4 options, so there is a total of 5 options including the no selection option.
Condition = value
values: none of these values
Set of values = '_none'
DEPENDENT FIELD SETTINGS
Type: Required textfield
form state: visible
The javascript works nicely, and when no selection is made in the dependee select, the dependant textfield is hidden. When you make a selection in the dropdown, they become visible.
However when submitting the form with no selection in the dependee (therefore the other textfield if hidden and should be required) the form produces an error stating that the text field is required. This is the same issue I reported in #1227692: Required fields still required even when they are hidden.
Comment #12
mrfelton CreditAttribution: mrfelton commentedHere is a patch that resolves the issue.
Comment #13
mrfelton CreditAttribution: mrfelton commentedSorry, here id the patch again, last one was corrupt somehow.
Comment #14
peterpoe CreditAttribution: peterpoe commentedCommitted #13 with changes: I left the "_none" value when a Set of values is provided, since otherwise there would be no other way to choose "empty field" as option with Lists. Thanks!
Comment #16
xcel CreditAttribution: xcel commentedHello
Sorry to jump again into this issue.
I still do not get the same behavior, so I was wondering what I am doing wrong.
I have fields in Drupal Commerce Order that I expose in checkout with the help of Field group and Field group panes.
I have:
- one boolean field called 'action', also required (and people have to choose between 'create' (0) and 'renew' (1). Default value is 'create')
- one text field which is required called 'name'
I want to hide and remove the required state of 'name' when users select 'off'
I manage to hide it but I always get the validation error "Name is required" when I click on 'Go to next step' button.
I have tried the following methods:
A - 'name' is INVISILBLE when 'action' has VALUE 1 (value taken from widget)
B - 'name' is VISIBLE when 'action' has VALUE 0 (value taken from widget) AND 'name' is INVISIBLE when 'action' has VALUE 1 (value taken from widget)
C - 'name' is INVISILBLE when 'action' has VALUE 1 AND 'name' is OPTIONAL when 'action' has VALUE 1
==> None are giving the expected result and I always end up with "name is required"
I even tried to reverse the mechanism: remove the required state from the 'name' field settings and do the following:
D - 'name' is VISIBLE when 'action' has value 0 AND 'name' is "REQUIRED" when action HAS VALUE 0
For this method, people can select 'create' for action, leave 'name' empty and go to next step without anuy error . . .
Could somebody help lol. I'm getting desperate.
Thanks in advance
Allan
Comment #17
System Lord CreditAttribution: System Lord commentedI'm using dev (just installed) which I assume has #13 patch included? I still cannot submit a form when there is a hidden required filed.
I have a list(text) with 5 values.
1|1
2|2
3|3
4|4
5|5
I have six other fields.
Comments (not required)
Complaint, Name, Email, Phone, Instructions (all required)
1 and 2 = Complaint, Name, Email, Phone, Instructions (all visible when when these values selected).
3,4,5 = Comment (visible when these values are selected).
Still, when I select 3, 4, or 5 I cannot submit because all required fields (which is hidden with these values) requires input.
I've tried a million +one combinations including the inverse.
Please help.
Comment #18
eMuse_be CreditAttribution: eMuse_be commentedAlso still having this issue.
Comment #19
emcniece CreditAttribution: emcniece commentedEncountering this as well. Could find a way to provide dev access if it would help!
Posted image help_dependencies.jpg for overview.
Comment #21
SocialNicheGuru CreditAttribution: SocialNicheGuru commentedComment #24
SocialNicheGuru CreditAttribution: SocialNicheGuru commentedSorry. I am placing this back to the status that I found it in which is "Active".
@SystemLord might want to create another issue.
I am also experiencing this.