I am using taxonomy.module with a vocabulary 4 levels deep.

If I create a node and select a term (at any level) - upon save I see the term associated with the node.

But, if I edit the node - the hierarchical select option is not set to the previously selected term. This module is new to me - could I have missed some configuration?

Comments

jpsalter’s picture

I added this at line #189 in taxonomy.inc to set the default to the node's current term - see comment for line:

        // Hierarchical Select only makes sense if there's a hierarchy.
        if ($vocabulary->hierarchy > 0) {
          $form['taxonomy'][$vid]['#type'] = 'hierarchical_select';
          $form['taxonomy'][$vid]['#hierarchical_select_settings'] = array(
            'module' => 'taxonomy',
            'params' => array(
              'vid' => $vid,
            ),
          );
          $form['taxonomy'][$vid]['#default_value'] = $form_item['#default_value'][0]; // <-- sets the default value  
          
          taxonomy_hierarchical_select_update_form_item($form['taxonomy'][$vid], $vid);
        }
wim leers’s picture

Status: Active » Postponed (maintainer needs more info)

That should work just fine.

Do you have multiple select enabled? If not, this is a bug that only occurs in very specific circumstances.

jpsalter’s picture

You're right - I do not have multiple select set.

wim leers’s picture

Then it's the intended behavior. It does show up in the dropbox, right? Please post a screenshot! :)

wim leers’s picture

Component: Code » Miscellaneous
Assigned: Unassigned » wim leers
Category: bug » support
Priority: Critical » Minor
wim leers’s picture

Title: Hierarchical select does not set default to previously selected term on node edit » HS, multiple select enabled does not set default to previously selected term on node edit
xtfer’s picture

I'm having what i think is the same problem. It saves fine, but then does NOT show up in the dropbox or a list when you go back to edit (i.e. it is not displaying the current taxonomy information).

This is for items that are NOT Multiple Select's (the multi-select's are getting an "All Selections" list below them, which I assume is a work-around behaviour, but will do fine).

The term depth doesn't seem to matter. Also this is for RC2...

wim leers’s picture

Version: 5.x-2.0-rc1 » 5.x-2.0-rc2

Same reply for you: please post a screenshot – or a several screenshots (one for submitting the node, one for re-editing it), so I can be very sure what exactly is the problem.

Also, please upgrade to RC3 and verify that the problem still exists. It's unlikely that it's fixed, and if it is, it'd have been indirectly.

mansion’s picture

Same here.

Once the node is saved, if it is edited again with hierarchical select, the select box will not show the previously selected values. This was observed both with multiple and single selects.

I don't see any dropbox neither. The vocabulary admin page proposes a "Dropbox settings" fieldset but there is no options displayed in there, only a description.

So I guess this might be related to the dropbox?

wim leers’s picture

Once again: I want screenshots!

wim leers’s picture

Category: support » bug
Priority: Minor » Critical

This is the final issue in the queue that prevents the 2.0 final release. Please post screenshots, so I can fix it!

Also, please upgrade to RC3 first.

mansion’s picture

The problem is in RC3.
Why do you want screenshots ?

You submit a new node. The next time you edit it, the hierarchical selects instead of being set to the default values are empty. I don't think a screenshot is needed to visualise that. I am only surprised it works for you.

Setting the default values for filters while in Views works though.

This was tested in Firefox and Safari, I don't have IE at hands.

wim leers’s picture

Then please post *all details* of your Hierarchical Select settings.

jpsalter’s picture

Version: 5.x-2.0-rc2 » 5.x-2.0-rc3
Component: Miscellaneous » Code
StatusFileSize
new36.01 KB

Attached is a screen shot of what I'm experiencing. This was done using RC3

I have the vocabulary set to:

Hierarchy - Single
Allows related terms in this vocabulary - NO
Free tagging- NO
Multiple select - NO
Required - NO

The default value passed in the variable $form is an array. The API seems to like a single value.

A single line of code at line 222 is needed to set the default in this case (note: I don't know if this breaks vocabularies with other settings)


  // Change the term selection of nodes. Only affects hierarchical
  // vocabularies.
  if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id && is_array($form['taxonomy'])) {
    foreach ($form['taxonomy'] as $vid => $form_item) {

      // Only apply Hierarchical Select if it's enabled for this vocabulary.
      if (variable_get("hierarchical_select_status_$vid", FALSE)) {
        $vocabulary = taxonomy_get_vocabulary($vid);

        // Hierarchical Select only makes sense if there's a hierarchy.
        if ($vocabulary->hierarchy > 0) {
          $form['taxonomy'][$vid]['#type'] = 'hierarchical_select';
          $form['taxonomy'][$vid]['#hierarchical_select_settings'] = array(
            'module' => 'taxonomy',
            'params' => array(
              'vid' => $vid,
            ),
          );
          $form['taxonomy'][$vid]['#default_value'] = $form['taxonomy'][$vid]['#default_value'][0]; // <-- use first default value in array

          taxonomy_hierarchical_select_update_form_item($form['taxonomy'][$vid], $vid);
        }
      }
    }
  }
}
wim leers’s picture

Hmm... I'm wondering if this has changed since one of the earlier Drupal 5 versions. I'd appreciate it if you could test with Drupal 5.2 or so.

Will get this fixed tomorrow.

jpsalter’s picture

My testing was done on Drupal 5.7. Sorry, but I don't have a Drupal 5.2 install laying around.

wim leers’s picture

You can still download it from http://drupal.org/drupal-5.2

wim leers’s picture

I didn't notice it when I first commented, but you forgot to post your HS settings, which I need too!

wim leers’s picture

I just tried to reproduce this and failed once again... I tried:

- enforce_deepest = TRUE, save_lineage = TRUE
- enforce_deepest = TRUE, save_lineage = FALSE
- enforce_deepest = FALSE, save_lineage = TRUE
- enforce_deepest = FALSE, save_lineage = FALSE

i.e. all permutations of settings. This was on Drupal 5.6, using regular Taxonomy (not content_taxonomy).

wim leers’s picture

Somebody who had this problem (but was at beta 2) saw it fixed when he updated to RC4. So perhaps, it's accidentally fixed. Please test.

victorkane’s picture

OK, I had the same problem, editing wasn't showing more than one or two of my four level deep hierarchy; and I was in the process of mustering my screen shots, when rc4 showed up in my update status list. I downloaded it and presto, problem fixed! So "works for me".

wim leers’s picture

Status: Postponed (maintainer needs more info) » Fixed

In RC4, the lineage reconstruction algorithm has been rewritten. I bet that was the cause then.

And … cool to know you're using my module too, Victor! :)

victorkane’s picture

Just FYI, I want to confirm that I was using the lineage saving option, so that would go towards confirming what you are saying.

It is a cool module! So I am using it in various sites I am working on right now, and helps to lead to a whole new "in defense of taxonomy" approach as a lightweight and powerful outlining tool for many purposes that I have tended to overload onto nodereferences up till now.

saludos!

z.stolar’s picture

Version: 5.x-2.0-rc3 » 5.x-2.0-rc4
Status: Fixed » Active
StatusFileSize
new3.41 KB
new4.15 KB
new59.46 KB
new8.62 KB

I'm not sure whether this is about multiple select or not. Here are my results:

- With the module disabled, the default taxonomy term is presented as expected. See screenshot no. 1

- Enabling the module. See screenshot no. 2

- Going back to edit - the Dropbox is empty. See screenshot no. 3. However, saving the node in this state, keeps the old term.

- Choosing a new term via the widget, and going back to edit - the new term is in place, as expected. See screenshot no. 4

My conclusion is that the problem is with first time use with existing nodes.

wim leers’s picture

Nope, it's not. In this example, you've selected a *single* term that's *not in the root level*.

You have allowed the user to select a term in any level, *but* you've also configured it to save the term lineage. And for a term lineage, you need to have *multiple terms* selected that also form one or more lineages.

So the behavior is perfectly fine.

Please post a new issue next time!

wim leers’s picture

Status: Active » Closed (fixed)