I wanted to use editable fields with HS select, but on the first update call from HS, it would remove all default items from the dropbox. It seems $form_state['storage']['hs'][$hsid] was getting lost in the process of calling _hs_process_attach_css_js. I added it during the _hs_process_attach_css_js call based on $element['#default_values']. I'm sure there is a better way to do this, but this is what I came up with. Sorry no patch at this time.

  if (! isset($form_state['storage']['hs'][$hsid])){
    $defaultselections = _hierarchical_select_dropbox_reconstruct_lineages_save_lineage_enabled($element['#config']['module'], $element['#default_value'], $element['#config']['params']);
    $selectionitems = array();
    foreach ( $defaultselections as $key=>$value){
      $temparray = array();
      foreach($value as $subkey => $subvalue){
        $temparray[] = $subvalue['value'];
      }
      $selectionitems[] = $temparray;
    }
    $form_state['storage']['hs'][$hsid]['dropbox_lineages_selections'] = $selectionitems;
  }

Comments

kars-t’s picture

Status: Needs review » Needs work

Please provide a patch for this issue.

wim leers’s picture

Category: bug » support
Status: Needs work » Postponed (maintainer needs more info)
dshields’s picture

I believe that nathanhilbert was referring to http://drupal.org/project/editablefields

It seems that these two modules don't play nicely with one another.

wim leers’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

That project is all fragile hackery IIRC. We cannot support that.

Gunfigter100’s picture

Issue summary: View changes

For anyone else who comes across this issue, I fixed this problem by using hook_form_alter() to add a custom function to the #preprocess attribute array of the offending field.

array_unshift($form['field_my_field']['und']['#process'], 'mymodule_fix_editablefield_hs_lineage');

This custom function contains the code that nathanhilbert supplied above with some slight modification.

function mymodule_fix_editablefield_hs_lineage($element, &$form_state, $complete_form) {
  if (module_exists('hierarchical_select')) {
    $hsid = _hs_process_determine_hsid($element, $form_state);
    if (empty($form_state['storage']['hs'][$hsid]['dropbox_lineages_selections'])){
      $defaultselections = _hierarchical_select_dropbox_reconstruct_lineages_save_lineage_enabled($element['#config']['module'], $element['#default_value'], $element['#config']['params']);
      $selectionitems = array();
      foreach ( $defaultselections as $key=>$value){
        $temparray = array();
        foreach($value as $subkey => $subvalue){
          $temparray[] = $subvalue['value'];
        }
        $selectionitems[] = $temparray;
      }
      $form_state['storage']['hs'][$hsid]['dropbox_lineages_selections'] = $selectionitems;
    }

    return $element;
  }
}

The code must be prepended to the #process attribute of the field because if it runs after form_hierarchical_select_process() it does not take effect.

eit2103’s picture

Gunfigter100 cant thank you enough, you saved me hours!