Last updated May 10, 2010. Created by udig on May 10, 2010.
Log in to edit this page.

Say you need a drop down list composed of a view which functions as a navigation aid i.e. whenever an entry is selected (probably a node) the relevant page (of that node) is being loaded.
I was using this D5.x how to as the source. On top of that here's what I did:
1. Created a view called info_center_items. This view is using a 'fields' row style with single field included: the node title.
2. Created a module called jump_view and placed the below code inside:

<?php
function phptemplate_views_view_unformatted__info_center_items($view, $options, $rows, $title){
 
$form = drupal_get_form('jump_view_form', $view, t('CHOOSE AN ITEM')); 
  return
$form;
}
function
jump_view_form($form_state, $view, $initial_label){
 
drupal_add_css(drupal_get_path('module', 'jump_view') .'/jump_view.css');
 
// add the jQuery code which hides the 'Go' button and submits the form on change
 
drupal_add_js ('
    $(document).ready(function(){
      $("input.edit-submit-jumpmenu").addClass("hidden");
      $("#edit-nid-'
.$view->name.'").change( function () {
        this.form.submit();
      });
    })
  '
,'inline');
 
$options = array();
 
$options[0] = $initial_label;
  foreach(
$view->result as $node ) {
   
$options[$node->nid] = _filter_url_trim($node->node_title, 35);  // Just to trim titles longer than 35 chars
 
}
 
$form['#id'] = 'jumpmenu-'.$view->name; // give it a unique name, in case you want to have more than one on a page
 
$form['#attributes'] = array('class' => 'jumpmenu-form', 'name' => 'jumpmenu-'.$view->name ); // again - for uniqueness and styling
 
$form['nid-'.$view->name] = array(
   
'#type' => 'select',
   
'#options' => $options,
   
'#id' => 'edit-nid-' . $view->name,
   
'#class' => 'jumpmenu-item',
  );
 
$form['view_name'] = array( // again - allowing for multiples on a page
   
'#type' => 'value',
   
'#value' => $view->name,
  );
 
$form['submit'] = array( // the go button, which will be hidden via jQuery
   
'#id' => 'edit-submit-jumpmenu-' . $view->name,
   
'#attributes' =>  array('class' => 'edit-submit-jumpmenu'),
   
'#type' => 'submit',
   
'#value' => t('Go'),
  );
  return
$form;
}
function
jump_view_form_submit($form, &$form_state) {
 
$form_values = $form_state['values'];
  if ( @
$form_values['nid-'.$form_values['view_name']] && is_numeric($form_values['nid-'.$form_values['view_name']]) ) {
   
drupal_goto('node/'.$form_values['nid-'.$form_values['view_name']]);
  }
}
?>

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.

Comments

This works really well. Exactly the kind of nuggets I like to find.

Added to snippets.

Thanks

Or you can enable ctools (http://drupal.org/project/ctools) and an extra "jump menu" option will "magically" and undocumentedly (?) appear in you views "Style" options. Choose that "Style" and select "Hide the 'Go' button" in the styles settings and well... that is it!

Thanks for pointing this out - after a number of hours of looking for this function this really helped.

I also found the latest (11-July-2010) dev version of jump to provide similar functionality.

Can't see the jump style option in views? I'm using CTools 6.1.2?

Drupal developers www.lightflows.co.uk

There is a patch for documentation using this Ctools feature.

#622740: Please document "jump menu"

Do you know of any way to style this? Using css or would I have to modify the actual jump-menu.inc file to lets say change that drop down arrow button to a custom image. Cause I hid the Go button and I just want to change that default drop down arrow button to an image. any suggestions?

Subscribing... Nice!