diff --git a/core/includes/form.inc b/core/includes/form.inc index 244e0a3..4a81959 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -3864,7 +3864,6 @@ function form_process_autocomplete($element, &$form_state) { $element['#attached']['library'][] = array('system', 'drupal.autocomplete'); // Provide a data attribute for the JavaScript behavior to bind to. $element['#attributes']['data-autocomplete-path'] = url($element['#autocomplete_path'], array('absolute' => TRUE)); - $element['#attributes']['data-autocomplete-values'] = $element['#value']; } return $element; } diff --git a/core/misc/autocomplete.js b/core/misc/autocomplete.js index 51c4df9..119fe63 100644 --- a/core/misc/autocomplete.js +++ b/core/misc/autocomplete.js @@ -118,71 +118,19 @@ function focusHandler() { * @return {Boolean} */ function selectHandler(event, ui) { - var term = ui.item.value; - var $text = $(event.target); - - addItem($text, term); - buildList($text); - event.target.value = ''; - // Return false to tell jQuery UI that we've filled in the value already. - return false; -} - -function removeItem($text, term) { - var terms = $text.data('terms'); - - var position = -1; - $.each(terms, function(index, value) { - if (value == term) { - position = index; - } - }); - if (position != -1) { - terms.splice(position, 1); - $text.data('terms', terms); - } - buildList($text); -} - -function addItem($text, term) { - var terms = $text.data('terms'); - if (typeof terms === 'undefined') { - terms = []; + var terms = autocomplete.splitValues(event.target.value); + // Remove the current input. + terms.pop(); + // Add the selected item. + if (ui.item.value.search(",") > 0) { + terms.push('"' + ui.item.value + '"'); } - var isNew = true; - $.each(terms, function(index, value) { - if (value == term) { - isNew = false; - } - }); - if (isNew) { - terms.push(term); - } - //terms.sort(); - $text.data('terms', terms); -} - -function buildList($text) { - var terms = $text.data('terms'); - var $list = $('> ul.list', $text.parent()); - if ($list.length == 0) { - $list = $('