I'm sure this is an easy one for jQuery experts, but I'm a backend guy, and can't find the best way to do this. I have two arrays in Drupal, one is a list of names of views, and the other is an array that contains a list of displays for each view. Here's the code to populate the two arrays:
//load list of views in to array for select lists
$views = views_get_all_views();
$viewnames = array();
$viewdisplays = array();
foreach ($views as $view) {
$viewnames[$view->name] = $view->name;
foreach ($view->display as $k) {
$id = $k->id;
$title = $k->display_title;
$viewdisplays[$view->name]['id'] = $id;
$viewdisplays[$view->name]['title'] = $title;
}
}
Here's the snippet of the form that I'm working with:
$form['view'] = array(
'#type' => 'select',
'#title' => t('Select the view to be used for display'),
'#options' => $viewnames,
);
$form['view_display'] = array(
'#type' => 'select',
'#title' => t('Select the display of the gallery view to be used'),
'#options' => array(),
);
What I want to do, is dynamically fill the view_display select box with the appropriate values. If the user selected "My Favorite View" from the 'view' select, I want to display the $viewdisplays['My Favorite View'] array as the #options to the 'view_display' field.