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

  1. Write the patch
  2. Review and RTBC
  3. 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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mparker17’s picture

Title: Provide an option to show the current facet and pre-select it » Provide an option to pre-select the active facet
Issue summary: View changes

Turns out I had accidentally added the "Do not display active items" facet filter which was making the active facet disappear.

mparker17’s picture

Assigned: mparker17 » Unassigned
Status: Active » Needs review
FileSize
3.13 KB

Feedback welcome!

khiminrm’s picture

@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!

alcroito’s picture

Providing same patch with the != changed to == as suggested by khiminrm.

Jody Lynn’s picture

I'm confused. Can't you just turn off that facet filter as mentioned in #1? Why is the patch needed?

alcroito’s picture

After 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.

mparker17’s picture

@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.

mparker17’s picture

Assigned: Unassigned » mparker17
Status: Needs review » Needs work
FileSize
3.13 KB
607 bytes

For 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).

mparker17’s picture

Status: Needs work » Needs review

@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.

mparker17’s picture

@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 a selected 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.

mparker17’s picture

Assigned: mparker17 » Unassigned
Status: Needs review » Closed (duplicate)
Related issues: +#2118323: Add default option when facet is active

It 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.