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.
Hi,
I'm working on drupal 7 module similar to the conditional_fields module for drupal 6. This module will set #states attribute for the form field depend on the value selected from other form fields.
So far #states attribute works only for one field value that's why I made small patch for the states.js file which allows to define array of the values for the selector :
'visible' => array(
JQUERY_SELECTOR => array('value' => array('value_1', 'value_2', ....)),
...
),
I think it would be useful to add this patch to drupal 7 core.
Comment | File | Size | Author |
---|---|---|---|
#15 | states.patch | 381 bytes | peem83 |
#10 | form_example.tar_.gz | 10.95 KB | redndahead |
#3 | 1001172-mulivalue_states-1.patch | 1001 bytes | redndahead |
#2 | 1004842-advanced_options-1.patch | 40.15 KB | redndahead |
Comments
Comment #1
redndahead CreditAttribution: redndahead commentedThe patch is missing. I think this is really important can you please post it?
Comment #2
redndahead CreditAttribution: redndahead commentedHere is my attempt.
Comment #3
redndahead CreditAttribution: redndahead commentedhmm let's put the right patch this time
Comment #5
redndahead CreditAttribution: redndahead commenteddon't know why tests would be failing retesting.
Comment #6
redndahead CreditAttribution: redndahead commented#3: 1001172-mulivalue_states-1.patch queued for re-testing.
Comment #8
redndahead CreditAttribution: redndahead commented#3: 1001172-mulivalue_states-1.patch queued for re-testing.
Comment #9
redndahead CreditAttribution: redndahead commentedThis would be the eventual complete fix in d8. #735528: FAPI #states: Fix conditionals to allow OR and XOR constructions But I think this is a good middle ground for d7. The syntax changes compared to the d8 patch is minimal.
Comment #10
redndahead CreditAttribution: redndahead commentedHere is a module to test with. Apply the patch and go to yoursite.com/examples/form_example/states
Text will appear if you choose "Four" or "Lots" in the drop down.
Here is the form code used.
Comment #11
BenK CreditAttribution: BenK commentedSubscribing
Comment #12
rfayWhile this has clear merit, it's actually a little tiny API change, and I just would rather not do that now, especially when changes like this can be done in contrib. #735528: FAPI #states: Fix conditionals to allow OR and XOR constructions was probably the right way to do this and it didn't get in.
Sorry, but IMO this should wait, and please make a nice module and link to it here because everybody will want to do this.
Comment #13
AdrianB CreditAttribution: AdrianB commentedSubscribing.
Comment #14
redndahead CreditAttribution: redndahead commentedI'm going to mark this as a duplicate so it doesn't linger. Not really necessary if it isn't going in d7.
duplicate of #735528: FAPI #states: Fix conditionals to allow OR and XOR constructions
Comment #15
peem83 CreditAttribution: peem83 commentedThis patch allows to build OR constructions like in example in the issue description :
'visible' => array(
JQUERY_SELECTOR => array('value' => array('value_1', 'value_2', ....)),
...
),
the field will be visible if selector has value_1 OR value_2
Comment #16
redndahead CreditAttribution: redndahead commented@peem83 all work on this issue is now done here #735528: FAPI #states: Fix conditionals to allow OR and XOR constructions