Breaks Exposed Filters in Views 2

Kakulash - December 17, 2008 - 22:16
Project:Better Select
Version:6.x-1.0-beta2
Component:Code
Category:bug report
Priority:critical
Assigned:batchman_paradize
Status:needs review
Description

Looks great, but the filters no longer work. As soon as I disable this module it works again.

Anyone else getting this?

This module would be so awesome if it worked with Exposed Filters.

#1

dallen - December 28, 2008 - 21:10

I was wondering if it's the way the session variable is being stored?

When BetterSelect isn't enabled:[session] => views|a:1:{s:6:"guides";a:1:{s:6:"page_1";a:1:{s:3:"tid";a:1:{i:164;s:3:"164";}}}}

When BetterSelect is enabled: [session] => views|a:1:{s:6:"guides";a:1:{s:6:"page_1";a:1:{s:3:"tid";a:4:{i:164;i:164;i:0;i:0;i:162;i:0;i:137;i:0;}}}}

Although it does work for me if I only have two options. :)

#2

Mark Theunissen - February 27, 2009 - 15:17
Component:User interface» Code
Category:support request» bug report

Can you confirm this is still happening with the latest Drupal 6 -dev release? I can't reproduce. Taxonomy exposed filter works perfectly with better select in my testing.

#3

Mark Theunissen - February 27, 2009 - 15:21
Status:active» postponed (maintainer needs more info)

#4

ipwa - April 3, 2009 - 00:29

Hi Mark, Taxonomy Filter does work well, but I found that node type for example doesn't work.

#5

fourmi4x - May 3, 2009 - 12:26
Priority:normal» critical

I've got exactly the same problem : with exposed filters, the operators "is all of" and "is none of" just don't work anymore... (returning no results).

I would be reaaaaaally awesome if it worked, this is so practical ! Really good idea.

#6

etx - May 15, 2009 - 23:34

I am having a similar issue. When using better select with exposed filters the default content that should be displayed on initial page view does show up. The view returns 0 results. After pressing the apply button in the filter all the content is loaded.

When I disable Better Select the view works as it should, displaying all the available unfiltered content on the initial page view.

Great module by the way, thanks for your hard work!

#7

dixon_ - May 18, 2009 - 18:35

I can confirm this issue too. My setup is with two exposed filters:

* One multi value CCK text field as filter
* And one exposed taxonomy terms filter

I'll try to digg some deeper in to this issue later this evening.

#8

Mark Theunissen - May 21, 2009 - 15:02
Status:postponed (maintainer needs more info)» active

Ok I can confirm the bug exists. I've spent about an hour doing all the proper integration, but it hasn't helped.

I strongly suspect that this issue with supporting Views exposed filters is the same as Wim Leers and merlinofchaos have tackled trying to get Hierarchical Select to work. See the following:

http://drupal.org/node/342991#comment-1410606

If anyone wants to try fix it, I would suggest looking through that code too, but I can't really spend any more time at the moment.

#9

bohemicus - June 1, 2009 - 18:30

subscribing

#10

EvanDonovan - June 26, 2009 - 20:44

Any update on this? This bug has bitten me really hard today (as in, I had the module enabled in production for some time before I realized it was happening).

I may have a chance to look into it today, depending on what my other priorities are. If not, I may just have to disable the module, which is sad, because I love it.

#11

EvanDonovan - June 26, 2009 - 20:55

Ok, so I looked at that issue. It looks like the problem there is that people want to actually *use* Hierarchical Select on Views, and the uniqueness of the Views Form API makes that an impossibility.

I actually don't need to use Better Select on Views, either in the Views admin UI or in Exposed Filters. Thus, I would be happy with a solution in which Better Select only operated on the multi-selects in node edit forms. Would that be easier to code? If so, at least that would provide a stopgap for people such as myself who want to use both Views and Better Select, but are OK with not using Better Select *in* Views.

#12

alsears - June 26, 2009 - 21:08

I would agree that breaking views is a pretty big issue, so it would be great if someone does fix it.

#13

bohemicus - June 27, 2009 - 15:52

@EvanDonovan I may be missing something but isn't there a setting under admin/settings/betterselect to just enable better select for node edit forms? I'm using that on my two sites and it's working fine.

Of course, if I could use it on exposed views filters, the world would be a better place.

#14

EvanDonovan - June 30, 2009 - 20:47

@bohemicus: Oh, you are right! Thank you. This is what happens when I don't look at module configuration pages.

This bug should probably be noted in a "Known Issues" section of the README though, since it can be worked around, but there's no easy fix.

#15

Mark Theunissen - June 30, 2009 - 22:13

Patches welcome. ;)

#16

tfranz - August 4, 2009 - 10:51

I have the same problems with the exposed filter in views 2 ... looks great, but still not working ...
(subscribing)

#17

batchman_paradize - August 19, 2009 - 10:19

I looked in to this problem yesterday and ended up making some changes to Better Select in order for this to work. I have only tried my changes with Exposed Filters in Views 6.x-2.6 using Taxonomy. The problems occur if you use the "Is all of" or "Is none of" settings.
I searched high and low for someone who had already solved it, but couldn't find anything so I ended up solving it myself.

It's a rather ugly patch, but it works ;)

I only needed to make changes to betterselect.module...
First I added the following directly after the first if-clause in function betterselect_process

// To handle deselection of checkboxes in exposed Views-filters we need this
if ((substr($complete_form['#id'],0,18) == 'views-exposed-form') && isset($element['#value'][0])) {
$element['#value'] = array();
}

Then I added this to the very beginning of function betterselect_form_alter

// Add this to handle checkboxes in exposed Views-filters
if (substr($form['#id'],0,18) == 'views-exposed-form') {
$form['#submit'][] = 'betterselect_views_filter_from_checkboxes';
}

Then I added this function:

/**
* Additional submit handler for the views filter form.
*/
function betterselect_views_filter_from_checkboxes($form, &$form_state) {
  // Create a new and correct array, if we need to!
  if (!array_key_exists(0, $form_state['values']['tid'])) {
  $new_tid = array();
  foreach ($form_state['values']['tid'] as $val) {
  if($val != 0) {
  $new_tid[$val] = $val;
  }
  }
  // This is for the of chance that we actually selected something ;)
  form_set_value($form['tid'], $new_tid, $form_state);
  $form_state['values']['tid'] = $new_tid;
  $form_state[view]->filter[tid]->validated_exposed_input = $new_tid;
  }
}

In addition to this I added autosubmit using AJAX, but that is not really relevant here, is it?

That should be it! Please let me know if this doesn't work/does work for you as well!

#18

EvanDonovan - August 19, 2009 - 15:18

Can you roll this as a patch so I can test? Thanks so much!

#19

tfranz - August 19, 2009 - 20:50

I made the changes, but it didn't work for me – maybe i made a mistake? Do you mind attaching your file "betterselect.module" for testing?
Thank you! :-)

#20

dixon_ - August 19, 2009 - 21:25

@batchman_paradize: Try to make a patch out of your changes. http://drupal.org/patch

#21

batchman_paradize - August 19, 2009 - 21:38

I'm out travelling at the moment, will get back to you with a patch and an attachment as soon as I'm back! Hope you can wait that long ;) I might get a chance to fix it tomorrow evening.

#22

batchman_paradize - August 22, 2009 - 16:10

Here is my changed file as well as a patch, hope you can get it to work now :) If anyone find that there is something that still doesn't work with Exposed Filters and Better Select please report it here and I will see what I can do about it... I have just tested this with Taxonomy this far.

Due to restrictions on which file-extensions that are allowed you have to remove the ".txt" from the module-filename.

AttachmentSize
betterselect.module.txt 9.77 KB
betterselect.module.patch 2.27 KB

#23

tfranz - August 22, 2009 - 21:25

I copied your patched module-file, but it didn't work (for me). Instead it showed me the following errors:

warning: array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object in /is/htdocs/wp1135829_MDTEF2JOND/www/sites/all/modules/betterselect/betterselect.module on line 222.
warning: Invalid argument supplied for foreach() in /is/htdocs/wp1135829_MDTEF2JOND/www/sites/all/modules/betterselect/betterselect.module on line 223.
warning: array_shift() [function.array-shift]: The argument should be an array in /is/htdocs/wp1135829_MDTEF2JOND/www/includes/form.inc on line 1326.

I'm sorry, but i'm not good enough to "read" the errors ...

#24

batchman_paradize - August 24, 2009 - 09:02

I created a new patch that should take care of the above issue, though to make sure it really solves any problems I need to know exactly which settings you were testing in Exposed Filters. This goes for any problems reported, without detailed instructions on how to replicate the problem it will be hard to do anything about it.

Make sure to patch the latest release and not a previously patched file.

AttachmentSize
betterselect-348424-24.patch 2.31 KB

#25

tfranz - August 25, 2009 - 13:58

I tried your new patch (for beta2) and there are no warnings any more. But unfortunately it still doesn't work ...

I am using the following Views-filter:

$handler->override_option('filters', array(
  'tid_1' => array(
    'operator' => 'and',
    'value' => array(),
    'group' => '0',
    'exposed' => TRUE,
    'expose' => array(
      'use_operator' => 0,
      'operator' => 'tid_1_op',
      'identifier' => 's',
      'label' => 'Schwerpunkt auswählen',
      'optional' => 0,
      'single' => 0,
      'remember' => 0,
      'reduce' => 0,
    ),
    'type' => 'select',
    'limit' => TRUE,
    'vid' => '3',
    'id' => 'tid_1',
    'table' => 'term_node',
    'field' => 'tid',
    'hierarchy' => 0,
    'override' => array(
      'button' => 'Standard verwenden',
    ),
    'relationship' => 'none',
    'reduce_duplicates' => 1,
  ),
));

Is there anything wrong/special?

You can find the situation "live" (without betterselect) here: http://www.lecker-ohne.de/seite/alle-rezepte

Thanks for any help,

Tobias

#26

batchman_paradize - August 26, 2009 - 21:01

tfranz: This should solve the issues you have...

In this patch I've added the possibility to exclude Better Select from all admin-pages (hopefully). Check the settings for the module. The code to detect if it's an admin-page is just something I came up with and is probably not the correct way to detect it... Anyone know how it should be done? Anyway, it works for me at the moment...

I've added support for multiple Taxonomy-filters as well as support for when you change "tid" to something else... (tfranz: These were the issues you had...)

Feel free to try it out and report back how it works for you ;)

AttachmentSize
betterselect-348424-26.patch 5.59 KB
betterselect-348424-26.module.txt 11.68 KB

#27

batchman_paradize - August 27, 2009 - 23:24

I had some extra time to kill today and made some more changes. What I've done so far:

  • Taxonomy-support now works in Views 2 (I think...)
  • content_taxonomy-support added for Views 2
  • support for multiple taxonomy-filters
  • support for radiobuttons if singleselect is selected
  • enable/disable radiobutton-support in Better Select admin
  • enable/disable Better Select on all admin-pages (in case there are incompatibility-issues)
  • some debug-functions which probably should be removed

Please note that there are still bugs when using multiple Taxonomy-filters in one View, these bugs have to be fixed outside of Better Select. They're there regardless if you use Better Select or not. To avoid some of the problems caused by these bugs consider to use content_taxonomy-fields instead...

The code is still a bit ugly and I've also been overzealous in my use of is_array, is_object and isset which are left there from when I traced myself down the variable-trees... But since it works I won't do anything about it at the moment...

One more thing: If things seems to be buggy, enable "Optional" in the filter and try again... If you think about it you should be able to come up with the answer to why ;)

AttachmentSize
betterselect-348424-27.module.txt 15.18 KB
betterselect-348424-27.module.patch 17.26 KB

#28

batchman_paradize - August 27, 2009 - 23:33
Assigned to:Anonymous» batchman_paradize
Status:active» needs review

Forgot to change the status... Please review my changes and get back to me...

#29

tfranz - August 31, 2009 - 12:11

The new patch seems to work, if i use only ONE Taxonomy-Filter. In the sample-page (see link above) there are two taxonomy-filters and i still don't get it to work ... (see attachment line 457 ff)

To say something positive: i like the feature "Node form only" – so i can use "Better Select" at other places ... and there it works perfect! :-)

Best regards,

Tobias

By the way: the content-filter (see attachment line 516) ignores Better Select permanently ... but that is an other issue ...

AttachmentSize
view_export.txt 15.82 KB

#30

batchman_paradize - August 31, 2009 - 18:17
Version:6.x-1.0-beta1» 6.x-1.0-beta2

tfranz: I'm unable to reproduce your problems with multiple Taxonomy-filters at the moment, I will try to give it one more try this week but I'm very busy and will be away on 10-day trip from Friday...
I'm running this on a WIP-page (it's in Swedish):
http://masterveil.paradize.org/produkter

At the moment the main difference is that I use a CCK-Taxonomy-field and the normal Taxonomy-field instead of two Taxonomy-fields. I do this since If I run both filters as normal Taxonomy-fields it doesn't work regardless of whether I use Better Select or not.

Additional support for the field which is ignored has to be written, most probably it might work with just allowing the same functions which handle other Filter-fields using Better Select to handle that type of field as well. The structure for how to do that is in the current code I've submitted...

btw: If you want a more flexible exclude-function check out #540918: Exclude fields from conversion?.

PS. I changed the version of Better Select since I noticed that this thread was originally for beta1 and all code I've provided is based on beta2 (dev). DS.

#31

Bacteria Man - September 18, 2009 - 21:21

I can confirm Better Select does in fact break views exposed taxonomy filter functionality. The empty text appears when initially loading the view page (which could be a symptom of the bigger problem) and checking known terms with associated nodes returns empty results.

#32

phayes - September 30, 2009 - 00:53

subscribing

#33

trupal218 - November 11, 2009 - 07:23

subscribing

#34

RyanJLind - November 20, 2009 - 20:12

I am also having issues with Exposed Filters in Views 2, but I think it's maybe different. For me, the module is simply not doing anything at all. The posts in this thread reference the fact that it looks good, but doesn't work. Mine still works, but it's still just the multi-select list. The module hasn't overwritten it to be checkboxes. I can't seem to find any other issues related to this, but will post here in case it's somehow related to this or maybe I'm just a moron. I'm not using any taxonomy or anything. It's honestly a very basic select list for picking the status of a job posting to filter on.

edit: it seems that my field returns a associative array, so my keys are not numeric. In this module, there is a check that aborts the process for this occurance:

foreach($element['#options'] as $key => $val) {
if (is_numeric($key) || !is_string($val)) {
return $element;
}
}

Since I don't really see the point in making sure keys are numeric, I am taking this check out. I don't know what in drupal causes my array to be different (CCK?) but there it is. Sorry if this post is in the wrong place. Hopefully it can be moved to a good spot or just deleted.

Thanks.

 
 

Drupal is a registered trademark of Dries Buytaert.