Follow-up to #1532124: Error in views on adding a field with (option limit) as filter criteria.

React to changes in matching field without applying the change with the button. ie. implement ajax in views exposed filters.

Thanks to #1183418: Ajax attached to exposed filters in form_alter doesn't trigger callback it isn't that hard.

Also addresses:

* #1817270: Hide options in exposed filter (Views 3)

CommentFileSizeAuthor
#10 reference_option_limit-2035157_10.patch8.47 KBjonhattan
PASSED: [[SimpleTest]]: [MySQL] 39 pass(es). View
#8 reference_option_limit-2035157-8.patch5.76 KBjonhattan
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch reference_option_limit-2035157-8.patch. Unable to apply patch. See the log in the details link for more information. View
#2 reference_option_limit-2035157.patch5.19 KBjonhattan
#1 reference_option_limit-2035157.patch5.06 KBjonhattan
Members fund testing for the Drupal project. Drupal Association Learn more

Comments

jonhattan’s picture

Status: Active » Needs review
FileSize
5.06 KB

This patch works for me, although it's a bit hacky.

jonhattan’s picture

Changes in this patch:
- use exposed filter identifier instead of handler_id.
- add limited_field key to #ajax array to know which form key to pick in the ajax callback.

jonhattan’s picture

+++ b/reference_option_limit_handler_filter_limited_options_term_reference.inc
@@ -16,6 +16,9 @@
+
+module_load_include('inc', 'reference_option_limit', 'reference_option_limit.views');
+

Added this because for some reason in the ajax callback views.inc file is not being autoloaded.

sirblackjack’s picture

Nice work, this is the feature I always wanted!

I tried it with two taxonomy "term reference".

However after applying the patch, when using view filters I now see the moving icon and the "Please wait" message when selecting the "Parent" term for 1-2 seconds (just like when adding content) but for some reason the "child" term doesn't refresh. I still have to apply the change with the button so the "child" term only gets items related to the "parent".

Any idea what could be wrong?

Thanks

jonhattan’s picture

Not sure, I've found it doesn't work if the limiting field is also added as a contextual filter, in despite it is not selected as a 'matching field' in the limited field.

jonhattan’s picture

Issue summary: View changes

Better description.

Risha’s picture

Hello jonhattan.

I applied your patch to get ajax funcionality and after your select the first field there is a blue circle loading something, however there is no effect as all options are displayed in the second field and not limited anymore. It worked before, however it was not usable since u had to refresh the page to get options limited in the second field.. Could you please help me out to figure why second field is displaying all options even tho ajax is loading somthing after first field selection? Big thanks.

Edit: I made it work. The trick is to apply both patches, the one which was posted in this issue and the patch for views: https://drupal.org/node/1183418

After that it works as ti should. Big thanks for ur contribution!

jonhattan’s picture

Issue summary: View changes
jonhattan’s picture

FileSize
5.76 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch reference_option_limit-2035157-8.patch. Unable to apply patch. See the log in the details link for more information. View

Status: Needs review » Needs work

The last submitted patch, 8: reference_option_limit-2035157-8.patch, failed testing.

jonhattan’s picture

Issue summary: View changes
Status: Needs work » Needs review
Related issues: +#1183418: Ajax attached to exposed filters in form_alter doesn't trigger callback
FileSize
8.47 KB
PASSED: [[SimpleTest]]: [MySQL] 39 pass(es). View

Added support for chained filters (ref: #1809338: Three fields in chain?). Note: this patch is independent of that other issue, although you need the patch over there to create chained data.

Also added compatibility for autosubmit.

naimalanda’s picture

Hello,

I'm trying to expose the same filter (country , city) twice in the same view's page to compare 2 different nodes. The problem is that the first country/city filter works good, whereas the second one shows the ajax message loading but doesn't limit options in city when I select a country. In addition, the first city choice brings me back to "all" choice.

Thanks

mas0h’s picture

I have applied patch #10 ,bu I get this AJAX error when selecting parent option:

An AJAX HTTP error occurred.
HTTP Result Code: 200
Debugging information follows.
Path: /en/system/ajax
StatusText: OK

joachim’s picture

Status: Needs review » Needs work
mas0h’s picture

UPDATE: I get this AJAX error only when the "Hide submit button" option is NOT enabled, but when enabled it works just fine, but I guess it should work either ways, enabled or disabled.

mas0h’s picture

UPDATE: Those are the log entries when I try to choose something from the dropdown when there is a submit button showing:

Type	php
Location	http://mywebsite/en/system/ajax
Referrer	http://mywebsite/en
Message	Notice: Undefined index: form_id in ctools_custom_formatters_init() (line 11 of /mywebsite/sites/all/modules/custom_formatters/includes/ctools.inc).
Severity	notice
Type	php
Location	http://mywebsite/en/system/ajax
Referrer	http://mywebsite/en
Message	Notice: Undefined index: form_build_id in ajax_get_form() (line 320 of /mywebsite/includes/ajax.inc).
Severity	notice
Type	ajax
Location	http://mywebsite/en/system/ajax
Referrer	http://mywebsite/en
Message	Invalid form POST data.
Severity	warning
cdeces’s picture

#10 works for me.
However, it works only for vocabularies, not for content types.
I wish it could also work for content type ;)

tilon’s picture

#10 works after applying patch #73 https://www.drupal.org/node/1183418 in views dev version.

jomarocas’s picture

any updates for this? ok for me to working for more than two filters i apply the patch #10. and put the patch #106 and install module from comment #119 and working good that i expect, only test with two options or more and clear cache, module and patch from https://www.drupal.org/node/1183418. and i can confirm that working but you need wait i patch for views