Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Currently, when you select an option from a facetapi_select widget, when the page reloads with the new facet active, it's not pre-selected in the facetapi_select widget.
It would be great if there was an option to pre-select the currently-active facet.
Proposed resolution
Add an option to the settings form to pre-select the active facet in the select box.
Remaining tasks
- Write the patch
- Review and RTBC
- Commit
User interface changes
Add a checkbox to a facet's display settings. If checked, it displays the current facet and pre-selects it.
API changes
Add a setting to the widget settings to display the current facet and pre-select it in the select box.
Comment | File | Size | Author |
---|---|---|---|
#8 | provide_an_option_to-2283201-8.patch | 3.13 KB | mparker17 |
Comments
Comment #1
mparker17Turns out I had accidentally added the "Do not display active items" facet filter which was making the active facet disappear.
Comment #2
mparker17Feedback welcome!
Comment #3
khiminrm CreditAttribution: khiminrm commented@mparker17, hi and thanks for your patch! I've spend almost half of the day to find how to make '#default_value' work in select element, but with no luck. Your idea to pre-select active facet works fine for me. But I didn't use the whole code of the patch. I didn't add option to admin settings. But for the first look it would work fine except
if(!empty($settings->settings['active_facet_selected']) && $settings->settings['active_facet_selected'] != TRUE){$active_facet_key = $url;}
I think there can be mistake in compare operator "!=", I think it must be "==", but maybe I'm wrong. Thanks!Comment #4
alcroito CreditAttribution: alcroito commentedProviding same patch with the != changed to == as suggested by khiminrm.
Comment #5
Jody LynnI'm confused. Can't you just turn off that facet filter as mentioned in #1? Why is the patch needed?
Comment #6
alcroito CreditAttribution: alcroito commentedAfter testing one more time, indeed it seems that the facet is set active without this patch. I'm not sure why at first I thought that it was needed.
Comment #7
mparker17@Jody Lynn, RE: #5:
I had originally reported the issue as "Provide an option to show the current facet and pre-select it"; but I changed it to "Provide an option to pre-select the active facet" when I realized that I had accidentally enabled the facet filter. See the changes to the issue summary I made in #1 for all changes.
Comment #8
mparker17For some reason, I can't get either my patch in #2 nor the patch in #4 to do what I expect on a fresh Drupal installation. So I'm going to debug this a bit further.
Also, I noticed that the patch in #4 doesn't apply with
git apply
for some reason. So, I've re-rolled it (and I've included an interdiff from #2).Comment #9
mparker17@khiminrm, RE: #3, you're absolutely correct: the
!=
should be an==
. :P Thanks for catching that :)Also, it's working now that I've set my "Pre-select the active facet" option. Sorry for the confusion: apparently I'm having a difficult time waking up this morning.
Comment #10
mparker17@Placinta, RE: #6, it's possible that when you tested without this patch, you selected the first option in the select box, which would have made it appear to work. Essentially, when you first select a facet, the
--Choose--
option disappears. The behavior for choosing an option to initially select when none of the option tags have aselected
attribute is undefined, but Firefox, Chrome, Safari, Opera, IE8, IE9, IE10 and IE11 all pre-select the first item. So, without the patch, if you chose the first item, it would appear to be pre-selected, but if you chose any other item, the "pre-selected" option would be wrong.Comment #11
mparker17It appears that this functionality has been included in #2118323-13: Add default option when facet is active, which works pretty well. Marking this one as a duplicate of that issue.