This patch adds four options to multiselect widget form. Each of options can be turned on separatly and all are off by default not to brake current settings.
1) Add count - adds number of items for each facet as seen in other widgets.
2) Remove selected - removes active (selected) item from options (good for compability with 'current search block' that shows current item and allows to remove it and 'chosen' module)
3) Autosubmit - hides submit buttons and submits form after each choice
4) Act as single select element - this one needs little more explanation below...
I noticed that connected field facets are broken with multiselect. It is because fields are separated with ':' symbol and it is encoded in url. ':' between connected fields should be encoded twice, dont know why, but thats how stock 'Links' widgets works too. There is long comment in function getOptionKey()
on why 'multiselect' widget implements it's own way of adding keys. Not to brake compability I added as option possibility to build keys as originally intended, togathet with other options, this makes sense. We can discuss about title of option "Act as single select element" is probably not very clear.
Comments
Comment #1
mansspams CreditAttribution: mansspams commentedUpdated patch with better option #4 name and key. It is now "Use original option keys" and does exactly that.
Comment #2
mansspams CreditAttribution: mansspams commentedBetter issue title.
Comment #3
mansspams CreditAttribution: mansspams commentedAaaaand... hopefully last fix to patch. Should have tested better :(
Fixed logic to properly remove selected elements and also made a bugfix that makes option #4 not really necessary. It turns out if we wrap 'field alias' in drupal_encode_path() we get proper working code. I left #4 right now to see if it helps with nice url paths over at #1805806: Make this module work with facetapi_pretty_paths.
Comment #4
mansspams CreditAttribution: mansspams commentedRemoved option #4 as bugfix makes option not needed for correct functionality. I will take a look at pretty paths later.
Comment #5
N20 CreditAttribution: N20 commentedPatch dont work with latest dev:
as also mentioned here there's no js directory or files creted.
facetapi_multiselect.inc.rej:
Comment #6
rp7 CreditAttribution: rp7 commentedTested the autosubmit functionality - works. Thanks!
Comment #7
heddn#4 works for me, except for Date fields. But in general, Date fields don't work with this module at all. New issue to follow on *that* problem. For now, marking RTBC.
Comment #8
heddnsee #1974358: Date fields aren't supported for the Date issue.
Comment #9
29axe CreditAttribution: 29axe commentedTested autosubmit : works but the other options in the dropdown list are removed after the refresh.
Comment #10
pschuelke CreditAttribution: pschuelke commentedThe patch applied correctly although with some notes:
patching file facetapi_multiselect.module
patching file js/facetapi_multiselect_autosubmit.js
patching file plugins/facetapi/facetapi_multiselect.inc
patch unexpectedly ends in middle of line
Hunk #2 succeeded at 71 with fuzz 2.
I only used the auosubmit option and will verify it works.
Comment #11
jlyon CreditAttribution: jlyon commentedI got an error when I was trying to apply #4 because of the way the patch was formatted.
This patch worked for me with
git apply -v
.Comment #12
dafederThis change in the options logic:
Made all my options disappear completely. The rest of #11 works perfectly for me. I don't understand the logic - only show items if "remove selected" is checked?
Comment #13
HazaSame as dafeder, patch from #11 made my options disappears.
Comment #14
HazaI guess that the "remove selected" just removes the options from the list/active item when they selected, which is not the default behaviour.
I've changed a bit the logic there and fix the missing options.
New patch attached.
Comment #15
HazaComment #16
milesw CreditAttribution: milesw commentedGreat features! I'm using patch #14 for counts and autosubmit. Working nicely, thanks.
Comment #17
boyan.borisov CreditAttribution: boyan.borisov commentedGreat features! Work perfect for me.
Comment #18
tauno CreditAttribution: tauno commentedOptgroups don't work well at all with taxonomies deeper than 2 levels, so I added an option to not use optgroups and instead prepend the options with hyphens like Drupal core does.
Could use some additional review.
Comment #19
tauno CreditAttribution: tauno commentedForgot to include the new javascript file from the earlier patches.
Comment #20
valderama CreditAttribution: valderama commentedPatch from #19 works nicely here!
Comment #21
k.minkov CreditAttribution: k.minkov commentedWhile using patch#19 and selected to display hierarchy with dashes (Nest hierarchical facets in optgroups - unchecked) and when you select a term for example 2 or 3 level deeper in hierarchy after submitting the form in the input is shown not only this term, but all his parents in the hierarchy.
With the following patch only the ones selected are displayed.
Comment #22
k.minkov CreditAttribution: k.minkov commentedForgot the autosubmit js file in the patch here is the patch with it.
Comment #23
Exploratus CreditAttribution: Exploratus commentedJust installed #22. Works well! :)
Comment #24
Helrunar CreditAttribution: Helrunar commentedPatch #22 works for me too
Comment #25
jibize CreditAttribution: jibize commented#22 is mostly working for me as well. The "Act as single select element" seems to be broken when multiple facets are selected. Maybe we should remove this option for now to get the reste committed ?
I mark this one as Needs work because of the above.
Comment #26
rodrigoaguileraThe array is not initialized in buildDefaultValue and I'm receiving notices because of this.
Comment #27
narkoff CreditAttribution: narkoff commentedI also was receiving the following error after applying #22 patch: Undefined variable: default_value in FacetapiMultiSelectWidget->buildDefaultValue()...
I then applied #26 patch and error went away. Thanks.
Comment #28
29axe CreditAttribution: 29axe commentedHello
Did you find a solution for the "connected fields" multiselect issue? I really need this feature but I don't know how to make it work. The option "Act as single select element" does not work properly.
Even a hint on where I should start would really be appreciated. Do you know if it is possible to build a different path for connected fields without using ':' but eventually another safe character?
Comment #29
timodwhit CreditAttribution: timodwhit commentedPatch in #26 seems to handle Issues: 1, 2, 3 well.
However, autosubmit seems to hide all submit buttons on multiselect fields. It was what I wanted but some people might be adverse to it.
Comment #30
alec-AW CreditAttribution: alec-AW commentedPatch #26 works for issues 1, 2
I did not test it for issue 3
For issue 4: the problem is in the encoding of the value field of the select options
The values are for a connected field facet name field1:field2:value
It should be field1%3Afield2:value
So when the form is submitted, this string sould be double-encoded like the links widget : field1%253Afield2%3Avalue
In facetapi_multiselect/plugins/facetapi/facetapi_multiselect.inc
Line 86
I added an urlencode() for the field alias.
return urlencode($this->facet['field alias']) . ':' . $item['#indexed_value'];
It solved my problem
Comment #31
alec-AW CreditAttribution: alec-AW commentedI had to add another urlencode.
If you are not using the "remove selected", you should add urlencode() also to the function buildDefaultValue()
Here is the complete code with precedent issue :
Comment #32
Mac_Weber CreditAttribution: Mac_Weber commented@Alec-Serval your code needs some changes, as you can see at #2198337-2: URL encode for multi select values
Comment #33
dobe CreditAttribution: dobe as a volunteer commentedThis attached patch implements what is brought up in #31 using the logic from #2198337-2: URL encode for multi select values. Seems like everything works now that I need.
Comment #34
geek-merlinComment #35
geek-merlinGreat thing!
Unfortunately: Autosubmit seems not to work with chosen.
Edit: no wonder: it looks like the autosubmit js from #26 is not in #33.
Comment #36
geek-merlinThis patch takes #33 and re-adds js from #26.
Please test and rtbc.
Memo: It would be quite useful if the js also disables other submit buttons on autosubmit.
Comment #37
jnettikI just discovered an issue with this patch and the auto-submit functionality. iOS has a bug in how it handles changes to multiselect fields. It considers the action of clicking into the field a change, so it fire's the jQuery .change() event and submits the form before you ever have a chance to select filters. The solution here is to use .blur() instead of .change(), as that will wait until the facet loses focus before submitting. Attaching an updated patch based on #36
Comment #38
jnettikAfter more testing, my patch seems to break autosubmit functionality with the chosen module...
Comment #39
geek-merlinSo we're back to testing #36 i suppose.
Comment #40
jnettikThe issue with #36 is how iOS handles multi select lists. Just clicking into the list to begin selecting options picks the first option, and fires the change event. So when the autosubmit option is enabled, it's impossible to actually use the filters on those devices. I found a solution that seems to work for me, but admittedly it's a little hacky since Drupal doesn't allow you to add option outside of `value` and `selected` on `options`.
The fix is based on this: http://stackoverflow.com/questions/34985606/ios-9-2-select-list-multiple.... Basically I'm adding an empty option to the beginning of the options list, and setting `value="disabled"`. Then in `#post_render` calling a function that parses the rendered select element, finds one with a value of disabled, removed the `value` attribute and sets the `disabled` attribute.
The drawbacks I've seen so far is that some browsers don't seem to hide the disabled option by default. Adding the following to my CSS fixes that.
The other one using "disabled" as the option value. That could create some naming conflicts, but I think the likelyhood of that is slim.
Comment #41
ankur.addweb CreditAttribution: ankur.addweb at AddWeb Solution Pvt. Ltd. commented@All, the above patch is working perfectly fine but it doesn't support special characters.
Please find the attached patch - this patch would allow special characters and working perfectly fine.
Let me know if anyone have any queries/concern for the same.
Thanks!
Comment #42
saurabh.dhariwal CreditAttribution: saurabh.dhariwal at AddWeb Solution Pvt. Ltd. commentedComment #43
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedComments at #2835107: Invalid HTML is generated and #2836051: Hard coded XMl (which were filed as separate issues but are actually about the most recent patch in this issue, specifically about the changes that were introduced as part of #41 above) suggest that maybe this needs more work?
Comment #44
ankur.addweb CreditAttribution: ankur.addweb at AddWeb Solution Pvt. Ltd. commentedAttached patch modifies the patch to solve #2835107: Invalid HTML is generated and #2836051: Hard coded XML.
Comment #45
NWOM CreditAttribution: NWOM commented(Deleted)
Comment #46
firestonej CreditAttribution: firestonej commented+1 for the patch from #44.
Comment #47
firestonej CreditAttribution: firestonej commentedUpdated version of patch from #44 to include "data-placeholder" element for integration with Chosen module. Maybe it should be default HTML5 "placeholder" attribute, please advise.
Comment #48
firestonej CreditAttribution: firestonej commentedThe widget doesn't render on some server configurations.
Since LIBXML_HTML_NOIMPLIED and LIBXML_HTML_NODEFDTD were introduced in version 2.7.8 of that extension, calling these constants is problematic. It can result in errors like these:
A simple fix is to just statically check the libxml/PHP version and ignore these optional constants if it's unlikely they'll be defined. Relevant code:
Patch included - tested on CentOS 6.8 with PHP 5.6 and libxml 2.7.6, which has the undefined constants.
Comment #49
firestonej CreditAttribution: firestonej commentedAnother patch to improve Chosen theming – the facet counts really shouldn't appear on selected items, since Chosen will prepopulate them above the search results dropdown. Interacts correctly with add_count option.
Another option would be to add a tag around the counts and do it with CSS, but I think that's only a good idea if the user is using Chosen, since it's not HTML-correct to have other tags inside the element.
Comment #50
firestonej CreditAttribution: firestonej commentedFixed broken logic from last patch, wasn't removing/adding counts correctly.
Comment #51
firestonej CreditAttribution: firestonej commentedOne more option for this module: allow showing empty facets as disabled, which will let Chosen consequently handle them that way.
Comment #52
firestonej CreditAttribution: firestonej commentedFixed some notices from the patch in #51.
Comment #53
marcmueller CreditAttribution: marcmueller as a volunteer commentedHi, I've got troubles to apply the latest patch. Firestonej, could you provide a patched tarball of the module?
Thanks, Marc
Comment #54
arturs.v CreditAttribution: arturs.v as a volunteer commentedSmall addition to allow translating the placeholder label. The patch applies cleanly to the latest commit in the development branch.
A.
Comment #55
NWOM CreditAttribution: NWOM commented@marcmueller: Please take a look at https://www.drupal.org/project/facetapi_multiselect/git-instructions
Comment #56
marcmueller CreditAttribution: marcmueller as a volunteer commentedThank you, NWOM. I've been using Netbean's apply patch function. Via git its working now.
Also, thanks to all of you contributors!
Comment #57
asherry CreditAttribution: asherry commentedI just noticed an added line accidentally and one coding standards violation, but otherwise I think this patch should really be committed by now.
I think this project is in need of another co-maintainer so I'll fill out another ticket with that as we have this module in a major production site.
Comment #58
asherry CreditAttribution: asherry commentedComment #60
asherry CreditAttribution: asherry commentedHello all -
Thanks to all who contributed to this patch. This was such a great combined effort that it would have been a shame not to make sure everybody got credit for the work they did.
I did my best to divide up the patch and make sure the commit was attributed to the actual code people changed.
Thanks everybody!
Any issues with the new codebase should now all be filed in separate tickets.