I have a custom form in Drupal.
When a user first sees this form, the only thing on the page is a select box, along with a few other elements they have to fill out.
When they make a selection from the select box, the #ajax callback regenerates the form, and adds about 50 results to the page.
By default, Drupal is scrolling down to the last result. This is a problem, because the users have to scroll back up to the elements near the top of the page to finish their work.
Is there a way to prevent Drupal from scrolling to the bottom of the newly-added form content?
Here is a snippet that shows how I'm setting up the form:
$form = array(
'#tree' => TRUE,
'#prefix' => '<div id="myform">',
'#suffix' => '</div>',
);
Here is a snippet from the select box that triggers returning the results.
$form['selectbox'] = array(
'#type' => 'select',
'#title' => t('Select box'),
'#options' => $predefined_select_options,
'#empty_option' => t('Select something!'),
'#ajax' => array(
'callback' => 'mymodule_form_ajax',
'wrapper' => 'myform',
'effect' => 'fade',
),
);
$form['other_stuff'] = array(
'#type' => 'textfield',
'#title' => t('Other stuff they need to fill out here'),
);
if (isset($form_state['values']['select box'])) {
foreach ($lots_of_results as $result) {
$form[$result] = array(
'#type' = 'fieldset',
'#title' = 'Lots of results in their own field sets',
);
}
// It scrolls to the bottom of this huge list after it's rendered.
}
Here is the ajax handler for the select box.
function mymodule_form_ajax($form, $form_state) {
return $form;
}