Great module, but I am having a bit of a problem with using more than 1 field with the expander in my View. Here is the scenario:
- Content view
- 4 fields - title, body, standards, assessment
- Standards & Assessment I need to use the expander field for. Both are long text fields in a content type, similar to how the body field would be setup
When I make one of the fields (Standards) into an Expander, the first one shows the text ("Standards Overview") to expand down fine, and the functionality is there, meaning that the text expands. However if I try to make the 2nd field (Assessment) into an expander as well, it's Expand Text shows "Standards Overview" as well BUT it does show the text for assessment.
So essentially it looks like this
Unexpanded:
Standards Overview
Standards Overview
Expanded:
Standards Overview
Standards Overview text
Standards Overview
Assessment text
I'm not a programmer but I poked around in the HTML being output and it looks like around line 120, where it has this:
'#prefix' => '<div class="field-expander field-expander-' . $delta . '">',
the resulting output of more than one expander field shares the same number, so they both end up with "field-expander-0" as their class name. Not sure if that has anything to do with the duplicated titles but I did notice that.
Any help that you can offer for this would be greatly appreciated!
Thanks!
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | multiple_expander-1896646-3.patch | 1.47 KB | bircher |
Comments
Comment #1
leilyrken commentedI had the same problem. Chekcing the code the problem is the delta which is always 0.
the function
jquery_expander_field_formatter_view()is called for every field so the delta is always the same.I change the function in jquery_expander.module to use also the field ID to differentiate:
The difference are:
'#prefix' => '<div class="field-expander field-expander-' . $field['id'] .'-'. $delta . '">',Sorry I have no time to create the patch but it should resolve your problem.
Comment #2
nno commented@leilyrken Thank you
This fixed me an issue with having multiple expander fields ona same page with different "read more / read less" strings.
Comment #3
bircherThe suggestion in the comments above are not wrong per-se, but the problem is a rather simple bug:
The
static $delta = array();is supposed to be the$idfor the'field-expander-' . $idthat is used by the javascript.But $delta is used in the foreach as the key and thus reset to 0 for each field.
The attached patch solves this issue.
Comment #4
scratchfury commentedbircher's patch in comment #3 fixed my issue perfectly with no side effects, so chalk up one vote for changing the status to RTBC. Any chance this simple fix can be incorporated into the project? It will help everyone who needs to include multiple expanders on a single page, which seems like a reasonably common scenario.
Comment #5
gresko8 commented+1 RTBC
Using multiple expanders per page on one of our sites.