Hi!

This piece of code in tpl file gave same ids for all accordion groups of rows:

print $views_accordion_id ">
foreach ($rows as $id => $row):
print $classes[$id] "> print $row

endforeach;

Which is actually not pretty cool, because id is unique element. And this code can't pass html validation. It's error.
Unfortunately, I can't fix it, because when I try to remove this id or even rename it - my accordion crashed.

Comments

Daniel A. Beilinson’s picture

Sorry, i mean this div:

<div id="<?php print $views_accordion_id ?>">
<?php foreach ($rows as $id => $row): ?>
      <div class="<?php print $classes[$id] ?>"><?php print $row ?></div>
    <?php endforeach; ?>
<div>
manuel garcia’s picture

Version: 6.x-1.3 » 6.x-1.x-dev

Thanks for the report Daniel, unfortunately this is a known issue...

Here is the situation:

  • We use this ID for jQuery selection, for performance of the JS.
  • Views grouping renders at the moment as if they were several views instead of just one if I am not mistaken.
  • This results in our tpl file being hit once per group, hence the several ids being added.

The only ways around this is:

  • NOT to use an ID, which I am not terribly found of, since the JS can already be heavy if a lot of results are displayed. jQuery selectors are much more efficient using IDs than classes.
  • Drop support for grouping, which is a great feature, but a great headache also.
  • Figure out a way to create unique IDs for each group, not sure if it is even possible. Tell the JS about it.

I feel this is not going to be a 10 minute fix. This will require time to experiment, research different options and well, probably several days of working and debugging. Views accordion has become very powerful, but also complex.

At the moment I don't have the time to put aside to work on this, but I am opened to suggestions, perhaps between all of us we can figure it out.

As a start in this direction, and for the time being, if you are not using the group field as the header, you can change your tpl (copy it to your theme dir), into this:

<div class="item-list views-accordion <?php print $views_accordion_id ?>">
  <?php if (!empty($title)): ?>
    <h3 class="<?php print $views_accordion_id ?>"><?php print $title; ?></h3>
  <?php endif; ?>
  <?php if(!$options['grouping'] || ($options['grouping'] && $options['use-grouping-header'])): ?><div id="<?php print $views_accordion_id ?>"><?php endif; ?>
    <?php foreach ($rows as $id => $row): ?>
      <div class="<?php print $classes[$id] ?>"><?php print $row ?></div>
    <?php endforeach; ?>
  <?php if(!$options['grouping'] || ($options['grouping'] && $options['use-grouping-header'])): ?></div><?php endif; ?>
</div>

This will get the accordion stil working in the case of normal grouping, without using the group field as the header. You will have to fix the CSS though. Using the group field as the header will need much more work.

Note that I haven't fully tested that code, but well, looked ok at first glance.

I hope this triggers the discussion, and some of you help out on this issue. It's been lurking in the shadows for some time, it is time we face it!

manuel garcia’s picture

Status: Active » Postponed

I think for the time being we'll have to live with how views does this. Perhaps in D7 we'll tackle this.

acouch’s picture

In the views-view-accordion.tpl.php file there is an unused $id variable that will count each row of the view. That $id can be used for an even/odd class.

If you need a unique class for each row you could create a class out of the title " print preg_replace('/[^a-z0-9]+/', '_', strtolower($title))" or use the title to look up the nid. Neither of those are great solutions but are good for a quick fix. Other than that I think you might have to create a row style in order to iterate through each row to add a unique identifier.

luksak’s picture

Status: Postponed » Active

hi

why is this bug postponed? with this you cannot have multiple accordions on one page!

thanks

lukas

manuel garcia’s picture

Status: Active » Postponed

elluca: Read the issue to answer your question.

Also, you can totaly have multiple accordions in one page.

Thanks

luksak’s picture

what should answer my question?

i get ids like: views-accordion-field_slider_reference-default. and it is the same for every accordion group. i guess you use the id for the jQuery selector and by doing so, the accordion breaks. am i right?

thanks

manuel garcia’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Status: Postponed » Fixed

It won't be tackled in d6 I'm sorry, however, this is fixed in D7. Feel free to test it out.

Status: Fixed » Closed (fixed)

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

bdone’s picture

Version: 6.x-1.4 » 7.x-1.x-dev
StatusFileSize
new3.4 KB

i've re-opened this, hoping the the maintainer will review.

included is a patch for the 6.x-1.4 version that adds support for multiple accordions.

it address the third bullet point of comment #2 above by providing a unique #id for each accordion group.

in our use case, we were trying to embed accordions within another view. but, only the first accordion was working correctly.

maybe this is helpful for someone still grappling with the d6 version and multiple accordions.

bdone’s picture

Version: 7.x-1.x-dev » 6.x-1.4
Status: Closed (fixed) » Needs review

new at submitting patches...is it appropriate to change the version here?

luksak’s picture

Version: 7.x-1.x-dev » 6.x-1.4

thank you bdone

i have fixed this as well on my install but in a quite ugly way. i will try your patch the next time i update my modules.

lukas

knalstaaf’s picture

Version: 6.x-1.4 » 7.x-1.0-rc1
Status: Needs review » Active

Would there be a D7 patch available? -> #1344676: Adding a unique class when using a grouping field

knalstaaf’s picture

Version: 7.x-1.0-rc1 » 6.x-1.x-dev
Status: Active » Needs review
jendlerons’s picture

Here's the patch I've employed. It's a similar idea to comment #10.

manuel garcia’s picture

+++ b/views_accordion.module
@@ -70,11 +73,15 @@ function template_preprocess_views_view_accordion(&$vars) {
+  $vars['views_accordion_id'] = 'views-accordion-'. $view->name .'-'. $instance . '_' . $view->current_display;

You are not using this var anywhere?

This patch needs heavy testing in different setups.

jendlerons’s picture

$vars['views_accordion_id'] is used in the tpl.

However, you're right. Devs should definitely test this before using in production.

Edit:
If you do test, please post the results in this thread!

john.money’s picture

+1 #15.

Tested Firefox, Chrome, Opera, IE9-- all work and gets rid of invalid HTML errors.

mpv’s picture

+1 #10 (didn't tested #15).

Tested on firefox 12.0, chrome 19, IE 7 and IE 8.

manuel garcia’s picture

Issue summary: View changes
Status: Needs review » Closed (won't fix)

6.x no longer supported.