CVS edit link for peem83
I've made drupal 7 module, similar to conditional fields module for drupal 6. I call it conditional states because module works base on the #states form attributes.
The Conditional states module allows to set 4 kinds of #state attribute. Target field can be:
- visible,
- invisible,
- disabled,
- enabled,
based on the selected value in other form fields (so far only selectable fields - checkboxes, radiobuttons, selectlist)
In the future I would like to add more possible states.
A lot of people asking about conditional fields for drupal 7, and I think my module will meet their expectations.
Comments
Comment #1
peem83 commentedField conditional state module
Comment #2
peem83 commentedField conditional state module with small fix.
Comment #3
avpadernoHello, and thank you for applying for a CVS account.
As per requirements, the motivation needs to include more than two sentences (possibly a paragraph) that describe the module features (the description should make clear what the module features are without to look at the code), and a comparison with the existing solutions.
I will report here a little checklist:
Comment #4
peem83 commentedField conditional state module allows you to set '#state' entity form attribute for 'controlled field' based on value selected in other entity form fields ('control field') with allowed values.
You can set four kinds of the attribute for 'controlled field':
- visible - controlled field will be visible if value from control field corresponds to the values selected in the field conditional states settings form for that specific controlled field,
- invisible - controlled field will be invisible if value from control field corresponds to the values selected in the field conditional states settings form for that specific controlled field,
- enabled - controlled field will be enabled if value from control field corresponds to the values selected in the field conditional states settings form for that specific controlled field,
- disabled - controlled field will be disabled if value from control field corresponds to the values selected in the field conditional states settings form for that specific controlled field.
Example:
You have entity type with two fields - type of the first one is textfield, lets call it 'Telephone number', second one is selectlist with label 'Do you have mobile phone ?' with two options - 'yes' and 'no'. Lets say that you don't want to display 'Telephone number' field if user has selected option 'no' in 'Do you have mobile phone' field. With this module you can simply set this condition for the 'Telephone number' field in the field settings page (new tab 'Conditional states').
Comment #5
Breakerandi commentedgreat idea, when will it be official available?
Seems like the conditional field module maintainer won't bring an drupal 7 version out in the near future, but i need this functionallity so urgently..
Comment #6
peem83 commentedstill waiting for feedback :(
Comment #7
peem83 commentedI extended this module for new conditional state option - 'required'. This new option allows to set requirement for controlled field based on value selected in other form fields (control field). I also rebuild module files structure and added new hook - hook_field_state which allows to easily extend module functionality from other modules. To add new conditional state you need to define an array with state as array key and handler function name as value of this key:
function hook_field_state() {
return array(
'STATE' => 'STATE HANDLER',
);
}
New version of the module is attached.
Comment #8
peem83 commentedFixed one issue in version below
Comment #9
peem83 commentedone more small fix
Comment #10
peem83 commentedI have found few more issues in the module and I fixed them. Latest version of the module is attached below.
Comment #11
dgastudio commentedare u going to publish it as module in d.org?
Comment #12
YK85 commented@peem83 - can you please consider added AND/OR functionality into your module.
It seems like this functionality will not make it into conditional fields anytime soon #719068: show if ANY of controller fields are selected (OR vs AND controllers)
But it allows great flexibility in usage.
AND = all designated choices must be selected for the controlled field to show
OR = any of the designated choices may be selected for the controlled field to show
Comment #13
vitok-dupe commentedNice one!!! field_conditional_state awesome work!
Comment #14
ropaolle commentedWell done @peem83. field_conditional_state looks like a realy nice module.
Comment #15
goldlilys commentedThanks peem83 will test it out now. Need conditional fields for D7 but directed here.
Comment #16
Fidelix commentedJeez! Great work man, really...
Comment #17
peem83 commentedLast uploaded version contain some bugs in requirements functionality, below fixed release. It's nice to have support from you guys :) I'm still waiting for acceptance to release this module.
@nary - so far the module support only OR functionality which means that any of selected choices can control the fields. Of course if it will be released I will develop it as much as possible.
Comment #18
rburgundy commentedGreat work peem83!!
I'm also looking for the AND and OR functionality for controller fields, where AND would mean fields A and B needs to be selected for field C to show, and OR functionality where A or B can be selected for field C to show.
I'm really looking forward to following your work and can't wait for your module to be accepted as a contrib module.
Would you happen to be considering back porting your module to D6?
It seems your module will be far advanced compared to conditional fields module very soon and I feel that it will be a good 6months to a year until big sites with many contrib modules can upgrade with full functionality. If you can support a D6 version it would be truly appreciated!!
Comment #19
vitok-dupe commented+1
Comment #20
peem83 commented@rburgundy - unfortunately drupal6 doesn't have #state form attribute which is primary factor in this module.
Comment #21
vitok-dupe commentedD6 must die :D
now is D7 primary point!
Comment #22
sw3b commented+1
Comment #23
YK85 commentedOk, thanks for the information!
I found this as well for D7 #735528: FAPI #states: Fix conditionals to allow OR and XOR constructions
Comment #24
lloydpearsoniv commentedIs it possible for you to make this work with fieldgroups as well? Make it so that an entire fieldgroup & alll fields in them could be affected by conditionals. If you can, that would be excellent.
http://drupal.org/project/fieldgroup
Comment #25
vitok-dupe commented+1 good idea
Comment #26
jcarlson34 commentedAwesome work peem83!
Works great on my site. Looking forward to you getting a module landing page.
+1 to #24 for fieldgroup. The link is missing a underscore though so here's the link: http://drupal.org/project/field_group
Comment #27
eddin commentedSubscribe!
Comment #28
Wallace123455 commentedPeem83: Wow....awesome.
I agree with lloydpearsoniv, any way to get this to work with fieldgroups so the entire fieldgroup does not display?
Thanks again in advance for your time and efforts.
Comment #29
anruetherI'll try this soon, thanks für your work, peem83 !!
Comment #30
peem83 commentedI've extended the module for AND/OR functionality. Below full module description and attached new module version.
Field conditional state module allows you to set '#state' entity form attribute for 'controlled field' based on value selected in other entity form fields ('control field') with allowed values.
You can set five kinds of the attribute for 'controlled field':
- visible - controlled field will be visible if value from control field corresponds to the values selected in the field conditional states settings form for that specific controlled field,
- invisible - controlled field will be invisible if value from control field corresponds to the values selected in the field conditional states settings form for that specific controlled field,
- enabled - controlled field will be enabled if value from control field corresponds to the values selected in the field conditional states settings form for that specific controlled field,
- disabled - controlled field will be disabled if value from control field corresponds to the values selected in the field conditional states settings form for that specific controlled field,
- required - controlled field will be required if value from control field corresponds to the values selected in the field conditional states settings form for that specific controlled field.
Module supports AND/OR functionality for control fields which means:
- AND - all choices must be selected to control the filed (example: field A will be visible when in field B option 1 and option 2 is selected)
- OR - any choice will control field (example: field A will be visible when in field B option 1 or option 2 is selected).
Module contain new hook - hook_field_state which allows to easily extend existing functionality from other modules. To add new conditional state you need to define an array with state as array key and handler function name as value of this key:
function hook_field_state() {
return array(
'STATE' => 'STATE HANDLER',
);
}
Comment #31
vitok-dupe commentedYou the man!
Comment #32
vitok-dupe commentedJust install new version, try to add condition state and got this error
PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'condition_type' in 'field list': INSERT INTO {field_conditional_state} (field_name, control_field, state, bundle, trigger_values, condition_type) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5); Array ( [:db_insert_placeholder_0] => field_tags [:db_insert_placeholder_1] => field_blog_category [:db_insert_placeholder_2] => invisible [:db_insert_placeholder_3] => article [:db_insert_placeholder_4] => a:5:{i:2;s:1:"2";i:3;s:1:"3";i:6;s:1:"6";i:5;s:1:"5";i:4;s:1:"4";} [:db_insert_placeholder_5] => or ) in function field_conditional_state_settings_form_submit() (line 171 in file /home/vitok/public_html/blog/sites/all/modules/field_conditional_state/field_conditional_state.admin.inc).Comment #33
peem83 commentedThere's no update script for new version because it's not officially released yet, you need to delete field_conditional_state table form your database and entry in system table for this module, replace module files and install it once again. field_conditional_state table contain new column for condition type (AND/OR) that's why you need to go through all this steps. You can also simply add new column for field_conditional_state table, call it 'condition_type'.
Comment #34
YK85 commentedI was wondering if the new AND will allow the example: field A will be visible when in field B option 1 and field C option 2 is selected ?
Thank you!
Comment #35
peem83 commented@nary - in case of your example field is always controlled when both values from control fields are selected, example: lets say that you have 2 conditions for the field:
Field A is visible when field B has value 1
Field A is visible when field C has value 1
In this case field A will be visible only when field B has value 1 AND field C has value 1.
Comment #36
robertom commentedHi peem83, sorry for my bad english and thanks for your effort in this module.
How about creating a project on github waiting imminent migration from CVS to GIT and its new rules?
I'm new to drupal, but I need this capability.
I've attached two field A and B into 2 differents content_type, my need is to relate this (instances of) fields differently in the two content_type, but I've this error:
You already have this state type between these two fields.
Currently I've patched field_conditional_state for consider also bundle for validation. What do you think?
Comment #37
carwin commentedSubscribe
Comment #38
peem83 commented@robertom - that's right I forgot to check bundle type, thx for that, below patched module
Comment #39
robertom commentedI'm died ;)
Comment #40
peem83 commentedsorry for that :) debugging
Comment #41
vitok-dupe commentedLOL!
Comment #42
bigsyke commentedAmazing! works great!!!!!!
Can we somehow get this integrated with hierarchical select?
Edit: I think i may have accidentally added Hierarchial select by adding 'taxonomy_hs', to the field_conditional_state.admin.inc
line 230
Suddenly I can select my Hierarchical select category as my control.
However the conditional item never appears during node creation once I select the defined category.
Comment #43
Breakerandi commentedAny guess when this module gets an landing page?
Is there any disadvantage when using this module before it is "official"?
Comment #44
peem83 commented@ Breakerandi - I'm still waiting for review and looking forward for official release.
Comment #45
bigsyke commentedThis module seems very stable, in fact more stable than most of the other official releases. I've already created about 50 conditions on one node type, and its amazing!!!!!!! If it could be integrated with the D7 HS module then it would be a powerful combo.
Comment #46
robertom commentedIf I don't have misunderstood is needed to implement hook_field_delete_instance() rather than hook_field_delete_field(), otherwise remove an instance of a field attached to 2 different bundle leave orphans in the database.
we must clear field_conditional_state table when an instance of a field is deleted (if ther'is only one instance is called also hook_field_delete_field(), but for conditional_state isn't important).
I've also a little patch for coding standard
Comment #47
peem83 commented@robertom - thanks for your advice, I have implemented your patches and it works fine. Below patched release.
Comment #48
goldlilys commentedAfter updating to #47, I get this error:
Notice: Undefined property: stdClass::$condition_type in field_conditional_state_get_field_conditions() (line 361 of \htdocs\sites\all\modules\field_conditional_state\field_conditional_state.module).
Comment #49
robertom commentedcondition_type is added from field_conditional_state_7.
If you have some condition created first to "version 7" you could have condition_type attribute not setted.
try to investigate inside database and if is necessary populate this attribute.
Comment #50
robertom commentedI've 2 field:
I add 3 conditional states at field_2:
Now in the condition list I've 3 delete condition button.
I could click any button and the result is the same: is always deleted the first condition (in this case condition with ID 31)
Currently I can't distinguish the three buttons. For all buttons I've:
From Form generation I can read:
$form_state['clicked_button'] is deprecated, but I can't distinguish the three buttons also with $form_state['triggering_element']
I would add my personal patches.
Comment #51
peem83 commented@ robertom - one more time thanks for your help :) patched version attached.
Comment #52
Anonymous (not verified) commentedHi,
thank you for this really nice d7 field! Testing the module provided in #51 I was able to create conditions in standard node/add/foo forms. I want to use conditionals with profile2 module during the registration process too. Right now it seams not to work! Could the reason be that profile2 injects the fields in the user registration form and misses dependencies (js files)?
Exportables support:
Looking at the schema of this field it seams hard to ex-/import conditions. I think the numeric ids are problematic. Are there any plans to make this field exportable. Maybe a combination of bundle and fields could be an option (group_foo_field__bar_field) for a machine readable name?
Final question:
Is this meant to be a replacement for the d6 conditionals_fields module?
Thank you very much.
Comment #53
dgastudio commentedmikewink
why do u change the module title?????
Comment #54
peem83 commentedComment #55
robertom commentedWhen control field use a select widget could be a problem determine which will:
- the initial behavior of the controlled field
- the behavior of the controlled field when "- None -" or "- Select a value -" is selected.
To deepen the discussion may be helpful to read these comments:
http://drupal.org/node/140783#comment-3470686
http://drupal.org/node/140783#comment-3519770
http://drupal.org/node/140783#comment-3533170
I would add some patch for try to alleviate this problem
Comment #56
robertom commentedUse profile2 was my first attempt.
When I saw that field_conditional_state did not work with him, I have added fields directly in "people accounts" (admin/config/people/accounts/fields).
I haven't investigated, but I think that profile2 don't work because it use a profile2 bundle inside an user entity type.
Currently field_permission_state don't save information about entity type and don't check for multiple bundle attached to 1 entity (I hope I haven't said crap)
I'm interested in export conditions.
If I haven't misunderstood the ctools capability, I think that the id in field_conditional_state isn't a problem (is used only for delete condition).
I don't have very clear ideas, but I hope that in the near future Is possible to export conditions.
Comment #57
peem83 commentedField conditional states with robertom patches and support for profile2 module. I advise to reinstall field conditional states after updating the files or update weight in system table to 100 for field_conditional_state entry. It's important for correct ordering of calling hook_form_FORM_ID_alter, in this case user_form for profile2 support.
Comment #58
peem83 commentedField conditional states with robertom patches and support for profile2 module. My advise is to reinstall field conditional states after updating the files or update weight in system table to 100 for field_conditional_state entry. It's important for correct ordering of calling hook_form_FORM_ID_alter, in this case user_form for profile2 support.
Comment #59
avpadernoComment #60
bryancasler commentedsubscribe
Comment #61
arianek commentedHi. Please read all the following and the links provided as this is very important information about your CVS Application:
Drupal.org has moved from CVS to Git! This is a very significant change for the Drupal community and for your application. Please read the following documentation on how this affects and benefits you and the application process:
Migrating from CVS Applications to (Git) Full Project Applications
Comment #62
Shadlington commentedSubscribe
Comment #63
aouko commentedsubscribe
Comment #64
peem83 commentedThe Field conditional state project is in my sandbox ( http://drupal.org/sandbox/peem/1073388 ) where you can download it and test it. Now I'm waiting for review of the code and I hope it will be released as full project in soon.
Comment #65
havok commentedGreat project, worked like a charm, thank you very much for the hard work :D
Comment #66
lloydpearsoniv commentedI get these errors, When using booleans as control fields
Notice: Undefined index: field_yn_cms_experience in field_conditional_state_handle_requirements() (line 187 of /var/aegir/platforms/drupal7/drupal-7.0/sites/all/modules/field_conditional_state/field_conditional_state.module).
Notice: Undefined index: field_yn_gd_experience in field_conditional_state_handle_requirements() (line 187 of /var/aegir/platforms/drupal7/drupal-7.0/sites/all/modules/field_conditional_state/field_conditional_state.module).
Notice: Undefined index: field_researching_techniques in field_conditional_state_handle_requirements() (line 187 of /var/aegir/platforms/drupal7/drupal-7.0/sites/all/modules/field_conditional_state/field_conditional_state.module).
Notice: Undefined index: field_yn_layout_template_theme in field_conditional_state_handle_requirements() (line 187 of /var/aegir/platforms/drupal7/drupal-7.0/sites/all/modules/field_conditional_state/field_conditional_state.module).
Notice: Undefined index: field_yn_web_app_exp in field_conditional_state_handle_requirements() (line 187 of /var/aegir/platforms/drupal7/drupal-7.0/sites/all/modules/field_conditional_state/field_conditional_state.module).
Notice: Undefined index: field_yn_web_design_exp in field_conditional_state_handle_requirements() (line 187 of /var/aegir/platforms/drupal7/drupal-7.0/sites/all/modules/field_conditional_state/field_conditional_state.module).
Comment #67
peem83 commentedAll the issues you can add in my sandbox for this project http://drupal.org/sandbox/peem/1073388
Comment #68
blevins.charlie commented@peem83 Thanks for your hard work!
Comment #69
avpadernoComment #70
avpadernoComment #71
peem83 commentedIssue for that project has been moved here: http://drupal.org/node/1074342
Sandbox for that project is here http://drupal.org/sandbox/peem/1073388
Comment #72
jackbravo commentedSubscribe
Comment #73
dave reidComment #74
jox commentedThis is a great module. Installing and configuring it is easy, the integration is good and everything works as expected. Really nice job.
One little concern (no offence or demand). For my taste, the code is a bit too much squished. Adding some space would make it much more readable.
For example this code:
Looks much clearer like this:
It might be a matter of taste or habit. But I suppose that most people looking at that code would appreciate a more readable formatting. Adding lines of comments is also a valid spacing. :-)
Comment #75
Fidelix commentedHonestly, really, I prefer 10.000 times the first version than the second "beautified" version.
All this spacing and "beautification" doesn't make it more readable, really, at least not for me.
The only thing I'd change is this:
to this:
Comment #76
jox commentedI respect what you say. Though for me it has more to do with structure than with beauty. For me it enhances the readability kind of in a way how indentation does (of course not as significant): It uses formatting to emphasize structure. Maybe it does not need to be as extensive as in my example.
But that's just my humble opinion. I thought most others would agree, but I may be wrong.
Regarding the "else" thing. Your version (which I also prefer) does not comply with the Drupal coding standards. At least the Coder Review module does complain about it.
Comment #77
avpaderno