4

I tried to implement hook_form_alter in order to pass default value to Simple hierarhical select views exposed filter.

function mymodule_form_alter(&$form, &$form_state, $form_id) {
  $tid = get_tid_from_termalias (arg(1)); // here I get tid
  $form_state['input']['field_sity1_tid'] = (!empty($tid)) ? $tid : 'All'; 
  $form_state['field_sity1_tid']['#value'] = (!empty($tid)) ? $tid : 'All'; 
  $form['field_sity1_tid']['#default_value'] = (!empty($tid)) ? $tid : 'All';
  $form['field_sity1_tid']['#value'] = (!empty($tid)) ? $tid : 'All';
}

I see that shs.js creates 2 selects, one hidden and one shown. My code changes only the value in the hidden select while second select always remains 'All'. How to change the visible select's default value?

1
  • how can I set a default set of options for the shs dropdown select list?
    – harshal
    Commented Dec 26, 2014 at 14:25

1 Answer 1

0

Hmm, That's a challenge to set default with Simple hierarchical select using form alter.

As they are handling options to taxonomy in js.

But we have another way to set default value for the field. Passing in URL. Like : http://localhost/drupal/demo-view?field_test_tid=1

Hope this will help. Just trying other way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.