diff --git a/apachesolr_autocomplete.install b/apachesolr_autocomplete.install index 1ffe4c7..c4c7efe 100644 --- a/apachesolr_autocomplete.install +++ b/apachesolr_autocomplete.install @@ -14,4 +14,5 @@ function apachesolr_autocomplete_uninstall() { variable_del('apachesolr_autocomplete_suggest_keywords'); variable_del('apachesolr_autocomplete_suggest_spellcheck'); variable_del('apachesolr_autocomplete_counts'); + variable_del('apachesolr_autocomplete_autosubmit'); } diff --git a/apachesolr_autocomplete.js b/apachesolr_autocomplete.js index b77d46b..b69b479 100755 --- a/apachesolr_autocomplete.js +++ b/apachesolr_autocomplete.js @@ -37,7 +37,10 @@ Drupal.behaviors.apachesolr_autocomplete = { }).result(function(item, element) { // Handle selection of an element in the autocomplete widget. // We should submit the widget's parent form. - jQuery(this).get(0).form.submit(); + console.log(Drupal.settings.apachesolr_autocomplete.autosubmit); + if (Drupal.settings.apachesolr_autocomplete.autosubmit === 1) { + jQuery(this).get(0).form.submit(); + } }).addClass('form-autocomplete'); // Add Drupal autocomplete widget's style. } }; diff --git a/apachesolr_autocomplete.module b/apachesolr_autocomplete.module index 16397d6..9c461d5 100755 --- a/apachesolr_autocomplete.module +++ b/apachesolr_autocomplete.module @@ -21,7 +21,7 @@ function apachesolr_autocomplete_init() { drupal_add_js(drupal_get_path('module', 'apachesolr_autocomplete') .'/jquery-autocomplete/jquery.autocomplete.js'); drupal_add_css( drupal_get_path('module', 'apachesolr_autocomplete') .'/jquery-autocomplete/jquery.autocomplete.css'); // Specify path to autocomplete handler. - drupal_add_js(array('apachesolr_autocomplete' => array('path' => url('apachesolr_autocomplete'))), 'setting'); + drupal_add_js(array('apachesolr_autocomplete' => array('path' => url('apachesolr_autocomplete'), 'autosubmit' => apachesolr_autocomplete_variable_get_autosubmit())), 'setting'); } } @@ -471,6 +471,13 @@ function apachesolr_autocomplete_variable_get_counts() { } /** + * Wrapper around variable_get() for variable apachesolr_autocomplete_autosubmit. + */ +function apachesolr_autocomplete_variable_get_autosubmit() { + return variable_get('apachesolr_autocomplete_autosubmit', 1); +} + +/** * Alter the apachesolr.module "advanced settings" form. */ function apachesolr_autocomplete_form_apachesolr_settings_alter(&$form, $form_state) { @@ -499,4 +506,10 @@ function apachesolr_autocomplete_form_apachesolr_settings_alter(&$form, $form_st '#description' => t('WARNING: Counts shown alongside suggestions might be lower than the actual result count due to stemming and minimum match (mm) settings in solrconfig.xml.'), '#default_value' => apachesolr_autocomplete_variable_get_counts(), ); + $form['advanced']['apachesolr_autocomplete_autosubmit'] = array( + '#type' => 'checkbox', + '#title' => t('Submit search form automatically when a suggestion is selected'), + '#description' => t('If selected the search will be automatically submitted when a suggested term has been selected. To force a user to submit the search manually leave unchecked.'), + '#default_value' => apachesolr_autocomplete_variable_get_autosubmit(), + ); }