I have exposed filter with 0 depth.
Users can pick parent term for displaying results which is fine, but on child it says "none" so it looks like they have to choose child too. Changing word "none" to "any" would be much better but i do not know where to change this.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

svouthi’s picture

Hello,

This text is easily changed in the shs.js file found in the module's js folder.

Simply change "None" in the line:

"options[options.length] = new Option(Drupal.t('- None -'), 0);"

to whatever you would like. (I used "Please Select")

Sinan Erdem’s picture

Changing a text from the module files is not a good idea. Upgrading the module will remove this modification.

I think there should be an option to change this text. -any- or -all- is more logical words because even the user doesnt select this, all results will be shown.

svouthi’s picture

Since each use case is different, the preferred start content of the field will vary, so there will always be someone with the need to alter it. I am suggesting this simple modification until there is a more user-friendly way to designate the text. In my use case, the filter is required, so "Any" doesn't make sense since no content is shown until a selection is made.

svouthi’s picture

In the dev version, the text to change is found in shs_handler_filter_term_node_tid.inc in the line:

'any_label' => variable_get('views_exposed_filter_any_label', 'new_any') == 'old_any' ? t('<Any>') : t('- Any -'),

Change the "Any" text to whatever best suits your application.

stBorchert’s picture

Version: 7.x-1.6 » 7.x-1.x-dev
Issue summary: View changes
Status: Active » Closed (fixed)

Try the latest development version. It uses the default labels from views so there is "- Any -" now instead of "- None -" in exposed filters.

igorski’s picture

I needed a label saying “please select”. After elaborating for a couple of days, I came up with this solution:

if (typeof Drupal.settings.shs != "undefined") {
  for (a in Drupal.settings.shs) {
    for (b in Drupal.settings.shs[a]) {
      Drupal.settings.shs.[a][b].any_label = Drupal.t("- Please select -");
    }
  }
}

Not very elegant, but efficient.

Angry Dan’s picture

Component: Miscellaneous » Code
Category: Support request » Feature request
Status: Closed (fixed) » Needs review
FileSize
2.22 KB

See the attached patch which should provide this option.

weldUAE’s picture

I needed to change none to any and the development version does this very well and it will get all the results from the view. However, once I make a selection in the first level the second level will show with "any" but the result will be always 0 until I select the deepest level, in my case 4 levels.

weldUAE’s picture

Any updates?

Yuri’s picture

If I select 'Any' then no results are given. This should be all results.

Yuri’s picture

Status: Needs review » Active
davidneedham’s picture

I have the same problem as @weldUAE.

It's great that it says "any", however choosing a parent term will not show all nodes that selected child terms of the parent term. Bummer. Any ideas?

weldUAE’s picture

I don't remember where I found the solution but this is what you need to do to be able to show child terms in the result.

First you will need to update to the latest dev of shs. Then in views you need to select "Content: Has taxonomy terms (with depth; Simple hierarchical select)". In settings you will need to select vocabulary and set the depth. It is important to set the depth; If you have one level of child terms then set the depth to 1

inno81’s picture

I have the same problem as #10, and possibly #12:

If I select 'Any' then no results are given. This should be all results.

akalata’s picture

#13 works great, update to -dev and adjust the new settings. Thanks @weldUAE!

Kurt.j’s picture

#13 worked for me as well. Thanks.

davidneedham’s picture

#13 works for me as well. I didn't apply any patches, I just had to build the exposed filter in a different way.

This issue should probably be restructured to suggest better documentation (or possibly removing the option that we all ended up using the first time around).

  • stBorchert committed 9de9c7c on 7.x-1.x
    Issue #2004420: How to change "none" to "any".
    

  • stBorchert committed 5272619 on 7.x-1.x
    Issue #2004420: How to change "none" to "any".
    
stBorchert’s picture

Status: Active » Fixed

I've added the new hooks hook_shs_js_settings_alter() and hook_shs_FIELDNAME_js_settings_alter() (see shs.api.php for more details), so its now very easy to override "- None -" on a per-field level using a custom module.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

ashopin’s picture

#13 worked for me!

Victoriaxvx’s picture

#20 #20 Sorry but i can't understand how to use this hook.

I created a custom module with the code but nothing has changed

function hook_shs_field_provence_js_settings_alter(&$settings_js, $field_provence, $vocabulary_identifier) {
   foreach ($settings_js['shs'] as $field => &$container) {
     foreach ($container as $identifier => &$settings) {
       // Define labels for each level.
       $settings['labels'] = array(
         FALSE, // No label for first level.
         t('Country'),
         t('City'),
       );
       // Small speed-up for anmiations (defaults to 400ms).
       $settings['display']['animationSpeed'] = 100;
     }
   }
 }
 

I'll very thankful for any help.

stBorchert’s picture

@Victoriaxvx: you need to replace "hook" with the name of your module in the function name to make it work.
Additionally, you've renamed the second parameter of the function to $field_provence which will not work, since you use $field within the function.

So if your module is named "mymodule" the hook implementation will look like this:

<?php
function mymodule_shs_field_provence_js_settings_alter(&$settings_js, $field, $vocabulary_identifier) {
  foreach ($settings_js['shs'] as $field => &$container) {
     foreach ($container as $identifier => &$settings) {
       // Define labels for each level.
       $settings['labels'] = array(
         FALSE, // No label for first level.
         t('Country'),
         t('City'),
       );
       // Small speed-up for anmiations (defaults to 400ms).
       $settings['display']['animationSpeed'] = 100;
     }
  }
}
?>

hth,

Stefan

Victoriaxvx’s picture

FileSize
67.64 KB
97.48 KB

#25 Oh thank you so much!

now i have a little confuse with a name of field, is this name that have a content type, or name of exposed filter?

i tried with this examples, but it not work for me:

function custom_shs_field_provence_js_settings_alter(&$settings_js, $field, 
function custom_shs_term_node_tid_depth_js_settings_alter(&$settings_js, $field, 
function custom_field_provence_js_settings_alter(&$settings_js, $field, 

I really don't understand what is name i need to use.

This is the field on admin content type page:

scr1

And this is the exposed filter:

scr1

Sorry for stupid questions. but is really a little information on google

stBorchert’s picture

You may simply use hook_shs_js_settings_alter() (see shs.api.php for further reference) and print the field name. This is the easiest way to get the correct name.

Victoriaxvx’s picture

FileSize
103.34 KB

#27 hook_shs_js_settings_alter() isn't woork too.

i used that example:

function custom_shs_js_settings_alter(&$settings_js, $field_name, $vocabulary_identifier) {
if ($field_name == 'field_provence') {
foreach ($settings_js['shs'] as $field => $container) {
foreach ($container as $identifier => $settings) {
$settings_js['shs'][$field][$identifier]['any_label'] = t(' - Select an item - ');
}
}
}
}

But any time i have -none- label and can't change it.

I tried various combinations of field name like field_provence, field_provence_und_0_tid, field_provence_und_0_tid_select_1, but it never work for me, i haven't any idea how to change -none- for country and city.

shs

m.attar’s picture

Hi, You can use this solution using Javascript:

    $(document).ready(function () {
        $(document).ajaxComplete(function (event, xhr, settings) {
            if(settings.url.indexOf("js/shs/json") > -1){
                $([SELECTOR_TO_YOUR_SELECT_FIELD]).find('option:first-child').text(Drupal.t('DEFAULT_LABEL'));
            }
         
    }); 

LaPi’s picture

FileSize
38.8 KB
23.02 KB
34.03 KB

Hi everyone, I've got the same issue. When I select "any" in a child terms list there is no resoults. I can't fix with #13 because my filter comes from a field collection.
I have a content type with a field collection. One of the field in the field collection is a term reference.
I created a view with a relationship with the field collection and I create an exposed filter for term reference in the field collection (1.png) and I choose shs (2.png). I set filter as exposed (3.png). All work fine, but If choose any in a child list terms it display nothing and I can't set depth as #13 said.

Any ideas?

c@sper’s picture

Hi, I have the same problem as #10 and #14: selecting -any- gives no result ... but the solution given by #13 don't work form me, the problem persist.

I have drupal 7.59 and SHS 7.x-1.7 ... any suggestions?

[solved] I selected "allow multiple choice" in shs select ... selecting "single choice" it works