I'm trying to replace the value of the selected option in a jump menu from 'Choose' to something else (in my case, the value of a field). What would be the best way to do this? I was looking at views' preprocess & pre_render functions, but that doesn't seem to be the way to accomplish this. Unless I'm missing something.

(While looking into this, I noticed there isn't a tpl.php file for the jump menu style. Is this file intentionally missing?)

Comments

dawehner’s picture

You could try to hook_form_alter and check for the formid ctools_jump_menu

brunodbo’s picture

Status: Active » Fixed

Yep, indeed. .. thanks.

brunodbo’s picture

Status: Fixed » Closed (fixed)
brunodbo’s picture

If anyone else is looking to do this:

function mymodule_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'ctools_jump_menu') {
    $form['jump']['#options']['#default_value'] = array('' => t('Selected option'));
  }
}
merlinofchaos’s picture

Just to confirm yes, there is intentionally no tpl for the jump menu, because it would be more or less empty -- everything is processed by the form and it would just output one variable.

brunodbo’s picture

Thanks.

As an improvement to #4:

function my_module_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'ctools_jump_menu') {
    $form['jump']['#options'][''] = t('Selected option');
    $form['jump']['#default_value'] = '';
  }
}

will replace the jump menu's default '- Choose -' option with your own selected option (having a value of "" in the select box).

merlinofchaos’s picture

Category: support » feature
Status: Closed (fixed) » Active

I seem to recall that the underlying Jump Menu code allows the text for the '- Choose -' to be sent in via function in CTools. If this is true then it would be trivial to add an option in the UI for this.

brunodbo’s picture

StatusFileSize
new893 bytes

Something like this?

Attached patch adds a text field to the jump menu configuration UI, to supply the text for the 'choose' option. The value is then passed in the render() function and is displayed as the selected option in the select box.

brunodbo’s picture

Status: Active » Needs review
merlinofchaos’s picture

Need to add the choose field to the option_definition() for the style or it won't get stored properly in 3.x. Otherwise this is good, I think.

We should probably also just default it to '- Choose -' (set it translatable) and that way it's easy for the user to see what will be used.

brunodbo’s picture

StatusFileSize
new1.21 KB

Updated patch attached.

merlinofchaos’s picture

Oh wow. That - Choose - shouldn't be in t() (which highlights a bug -- the 'Go' above it also should not be in t(). That means those items will get double translated. That's never good.

brunodbo’s picture

StatusFileSize
new1.29 KB

Ah yes, that makes sense :)

Fixed the t('Go') bug as well (hope it's ok to do this in one patch?).

merlinofchaos’s picture

Version: 6.x-2.8 » 7.x-3.x-dev
Status: Needs review » Patch (to be ported)

Committed to 2.x and 3.x in D6. Since the jump menu hasn't made it to 7.x marking for porting

dawehner’s picture

Status: Patch (to be ported) » Fixed

And ported

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.