i have two jumpmenu's which filter a view:

Usecase:
1.) Jumpmenu: Country
2.) Jumpmenu: City (get's filtered by [1])
3.) some data which get filtered by [1] & [2]

When setting the value for city the jumpmenu for country doesn't get a default value. I tried to hook_form_alter the jump menu but the key's are kind of crypric. So setting #default is hard to set...

['ea0730f5662f7f655527b0ebe14c288f::/PATH/COUNTRYCODE/CITY']

It could be done with JS but i would like to know if there is another way!

Comments

muschpusch’s picture

Version: 8.x-1.x-dev » 7.x-1.x-dev

oeps... wrong version

D34dMan’s picture

Try something like this,


// Where $form['country']  is the select field for country
$options = $form['country']['#options'];
//assuming argument in url is at position 1
$cmp_val = '::/PATH/' . arg(1);
if(!empty($options) AND is_array($options)){
  foreach( $options as $key => $val){
    if( $key AND strpos( $key, $cmp_val) ){
      $form['country']['#default_value'] = $key;
      break;
    }
  }
}
muschpusch’s picture

Status: Active » Fixed

thanks! works great!

Status: Fixed » Closed (fixed)

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