Support from Acquia helps fund testing for Drupal Acquia logo

Comments

stBorchert’s picture

Status: Active » Closed (won't fix)

Sorry, but this won't happen. Simply hierarchical select is not meant to become a clone of Hierarchical select and duplicate all of its features and stuff.

gilsbert’s picture

Version: 7.x-1.6 » 7.x-1.x-dev
Status: Closed (won't fix) » Needs review

Hi.

In the past two months I tried HS and SHS and I would like to thank you all by the effort on SHS. At this moment I have better results with SHS.

The idea to keep it simple is good and probably is helpful to keep SHS with less bugs than SHS (honestly speaking HS is getting better but in my personal opinion SHS has a better support).

So I agree with the idea to keep SHS as simple as possible and not reproduce all the features that we find on HS.

But the labels for level are so necessary to make the user interface more friendly that I would like to vote for this feature.

Please, think about it.

Regards,
Gilsberty

ssoulless’s picture

Issue summary: View changes
Status: Needs review » Needs work

Hello I think this is a must, for usability reasons!!, the fact that shs is suposed to be "simple", the labels per levl is a feature very necessary and adding the labels will not make shs more "complex" it will keep being "simple"

I vote for this feature!

ssoulless’s picture

Check the patch here https://drupal.org/node/2096423

Actually the patch is deprecated, does not work with 7.x-1.x version but it is a good begining for this task.

silurius’s picture

Agree that labeling each level is an important usability requirement. My users are constantly asking me about this.

jack-pl’s picture

FileSize
1.22 KB

I have written a custom SHS behavior which solves two issues at once:

  • Creating labels per level
  • Changing the first select text from "- None -" to whatever you need

The code has been written for SHS view widget with 3 levels forsing to the deepest, but it's very easy to customize for any kind of displaying.

The instruction how to use it - SHS custom behaviours

taitai’s picture

I wrote a simple script to enable labels for level 2 and onwards.
Hope is useful for someone.

/**
 * @file
 * Simple script to add labels to shs select boxes
 * It creates new label element for each select box at the time the previous level was clicked.
 * This script shows three select level, you can add more levels by duplicating the code.
 * It assumes that there is already a label for the first select box, as usually provided by views.
 * You can position and attribute the new labels using the new divs in a separate css file.
 */

(function ($) {

    Drupal.behaviors.propMis = {

        attach:function (context, settings) {
            
            
             $(document.body).on('change','#select-1',function(){
                if (!$('#label-2').length > 0) {
                    $( "#select-2" ).before( '<div id="label-2">My label 2</div>')
                }
                if ($('#label-3').length > 0) {
                    $('#label-3').remove();
                    
                }
            });;
            
            $(document.body).on('change','#select-2',function(){
                if (!$('#label-3').length > 0) {
                    $( "#select-3" ).before('<div id="label-3">My label 3</div>')
                }
            });
              
        }
    };

})(jQuery);
matthewv789’s picture

I vote for this as well. As others have pointed out, it just has somewhat bad and confusing usability without it. It's not really a new feature, it's just making it nicely usable.

casimiro’s picture

Hello Taitai ,

how can I use your script ??

thanks

hash6’s picture

I used the #6 js file custom_shs_behaviors.zip but when I add that i have encountered an issue that shs does not store the lineage (it stores each new term created using Adding new term from shs as a parent term ) .
So basically lineage is not stored when I add any js code into the shs module
Please let me know if someone has encountered the same issue.
So for me #6 breaks the default functionality of shs and I need to add new terms and store it as a lineage.

Also, When I store a new term using "Add a new term" using shs add new term option the new term gets added but it does not show up the child terms related to that term.
Only when I change the new selected term to none and then back again to new term , I get the child term's dropdown list
otherwise it does not show up.
I am using shs 7.x-1.6

jack-pl’s picture

Hash6, Thanks for pointing this out. The SHS module has a bug: If you're creating a new level, then the select of that new level has the same ID as the previous one. I've added two lines to the code and now it should work with the ability of adding new levels as well.

have a look at the new code - SHS custom behaviours

jack-pl’s picture

FileSize
1.43 KB

Here's the new file

gpantikidis’s picture

Hello,
jack-pl, I try to implement your file but with no results at all. I place your file in my shs/js folder, change the labels, but nothing happens. Do you have any idea of what am I possibly doing wrong? This feature, to be able to add different label on each taxonomy-level is very useful.

jack-pl’s picture

FileSize
2.49 KB

gpantikidis, If nothing happened, that means the file hasn't been implemented to the form. I wrote a simple module, so you can have a quick view how the file works. All you need to do:

  1. Install the Shs Custom Behaviors module - enclosed to this comment
  2. Edit shs_custom_behaviors.module file and replace "YOUR-FORM-ID" with your shs form id

That's it! Now each select of your shs form (defined in hook_form_alter) should have labels ( defined in .js file)

hash6’s picture

FileSize
24.03 KB
37.12 KB

Hi jack-pl , the updated code on #14 works!!! and it stores the parent terms as well so its great work.

I am now facing another isssue which is as follows. I have altered one line for the labels to be displayed in proper position
I have removed the line on shs_custom_behaviors.js (below line 47)

https://www.drupal.org/files/issues/old%20working.png

   $(this).parent().before(
                          "<label for='" + $(this).attr('id') + "' style=' width: " + labelWidth + "px'>" + labels[level] + "</label>"
                        );

https://www.drupal.org/files/issues/new%20code%20breaking.png
and placed the below line instead of that

$('.shs-select-level-'+level).after("<label for='" + $(this).attr('id') + "' style=' width: " + labelWidth + "px'>" + labels[level] + "</label>");

When I use the above line instead of original the "add new terms " functionality breaks somehow and as it does not store parent terms i.e. newly added terms are not stored as child of above terms selected

jack-pl’s picture

Hello Hash6, I’m glad I could help. Now you are facing only a theming issue. You can’t use your code because of non-existing label for the first level. You can’t create a label after something that is not exist.

hash6’s picture

Last Updated: when I first tried it worked but now suddenly it seems to breking again the functionality of add_new_terms in shs
I am again stuck with the same problem mentioned above that parents terms are not stored.

Also one thing I would really like to know(and only if you could spare some time out of your busy schedule nothing urgent) how did my code affect the "add new terms" functionality.
If you could explain me the reason , it would help me in understanding the concept behind it.
code (add_new_terms functionality breaks here)

$('.shs-select-level-'+level).after("<label for='" + $(this).attr('id') + "' style=' width: " + labelWidth + "px'>" + labels[level] + "</label>");

code (add_new_terms functionality breaks here as well)

  if (level === 0) {
    $(this).before("<label for='" + $(this).attr('id') + "' style='width: " + labelWidth + "px'>" + labels[level] + "</label>");			  
  }
  else {
    $('.shs-select-level-'+level).after("<label for='" + $(this).attr('id') + "' style=' width: " + labelWidth + "px'>" + labels[level] + "</label>");
  }
jack-pl’s picture

hash6, You're facing only a theming issue. It should be easy to solve, but without html code it would be hard to help. Please use the default bartik theme to see that the code works fine, then find out in your theme what is causing the problem.

stBorchert’s picture

Status: Needs work » Closed (duplicate)

A working solution has been committed in #2096423: Accessibility - adding labels to selects. You'll need to override hook_shs_js_settings_alter() or hook_shs_FIELDNAME_js_settings_alter() and set the "labels"-property in the field settings.
See hook_shs_FIELDNAME_js_settings_alter() in shs.api.php for an example.

jack-pl’s picture

stBorchert, Are you sure that the hook_shs_FIELDNAME_js_settings_alter() is working?

The file description says:

/**
 * @file
 *
 * This file contains NO WORKING php code; it exists to provide additional
 * documentation for doxygen as well as to document hooks in the standard Drupal
 * manner.
 */
stBorchert’s picture

@jack-pl: Yes, the hooks are working. shs.api.php is a file to document which hooks are available and how to use them. Simply copying the code would not work since you'll have to replace "hook" with the name of your module and "FIELDNAME" with the name of your field (obviously).
I.e. if your module is named "example" and the field is named "field_location", the function would be named "example_shs_field_location_js_settings_alter".

Force_IAS’s picture

@stBorchert: the hooks aren't working, I tried with this code

function theming_scripts_shs_field_ubicaci_n_js_settings_alter(&$settings_js, $field_name, $vocabulary_identifier) {
  foreach ($settings_js['shs'] as $field => &$container) {
    foreach ($container as $identifier => &$settings) {
      // Define labels for each level.
      $settings['labels'] = array(
        t('Select Country'),
        t('Select State'),
        t('Select City'),
        t('Select Commune'),
        t('Select Neighborhood'),
      );
      // Small speed-up for anmiations (defaults to 400ms).
      $settings['display']['animationSpeed'] = 100;
    }
  }
}

And the labels still " - None - "

Am I doing something wrong or do I need to remove " - None - " label somewhere ?

stBorchert’s picture

Issue summary: View changes
FileSize
43.6 KB

@Force_IAS: trust me, they work fine. You are mixing up labels (HTML: <label/> with option values.
If you enable your custom module, reload the node form and look into the HTML you will see something similar to this:
 HTML output with labels

The labels are hidden by default, you need to display them using custom CSS.

To change "- None -" to a custom text, you will have to modify the value of the setting any_label (see shs.api.php: hook_shs_js_settings_alter() for an example).

Force_IAS’s picture

@stBorchert: Great!
Didn't know about the hidden labels!

Thank you Sir!

jack-pl’s picture

Issue summary: View changes

@stBorchert:

This is exactly what I've done.

My module name is: shs_custom_behaviors
My fieldname is: field_shs_test
Drupal version: 7.34

And my function is:

function shs_custom_behaviors_shs_field_shs_test_js_settings_alter(&$settings_js, $field_name, $vocabulary_identifier) {
  foreach ($settings_js['shs'] as $field => &$container) {
    foreach ($container as $identifier => &$settings) {
      // Define labels for each level.
      $settings['labels'] = array(
        t('First'),
        t('Second'),
        t('Third'),
      );
    }
  }
}

Unfortunatelly it doesn't work at all. There are no labels, neither visible nor hidden. Any ideas what I'm missing?

NIKS_Artreaktor’s picture

jack-pl

install module devel and check what field_name on the page

function custom_module_shs_js_settings_alter(&$settings_js, $field_name, $vocabulary_identifier) {
  dsm($field_name);
}
NIKS_Artreaktor’s picture

I have an Bug

If i using api
hook_shs_js_settings_alter()

for field in Views Exposed filter - it working - adding Label

But if you choose child (second select) - ALL -
It reset Main (first select) choice of select to ALL

FIX of this
Add JS code

$('select.shs-select-level-2').change(function(){
   if($(this).val() == 'All'){
      var countryval = $('#edit-shs-term-node-tid-depth-select-1 option:selected').val();								
      $('#edit-shs-term-node-tid-depth option:selected').val(countryval);
   }
   mainselect_val = $('#edit-shs-term-node-tid-depth option:selected').val();
});
luckydad’s picture

Thanks for this module.

My custom module to show labels for each level is very similar to jack-pl and is also not working. When I turn on Devel and check what field_name on the page per NIKS_Artreaktor instruction I see:

shs_term_node_tid_depth

Is that correct?
If not, what is wrong with function jack-pl posted?
Please advise.
Thanks in advance.