@@ -1845,18 +1845,12 @@ function initAutocompleteForField(inputId, field, config, dataFunction, errorEle
1845
1845
event . preventDefault ( ) ;
1846
1846
return ;
1847
1847
}
1848
- var pos = text . indexOf ( identifier ) ;
1849
- var phrase = escapeLuceneCharacters ( ui . item . phrase ) ;
1850
- input . val ( text . replace ( identifier , phrase ) ) ;
1851
- input . caret ( pos + phrase . length ) ;
1848
+ replaceValueWithSuggestion ( input , text , identifier , ui . item . phrase ) ;
1852
1849
1853
1850
event . preventDefault ( ) ; // to prevent the movement of the caret to the end
1854
1851
} ,
1855
1852
select : function ( event , ui ) {
1856
- var pos = text . indexOf ( identifier ) ;
1857
- var phrase = escapeLuceneCharacters ( ui . item . phrase ) ;
1858
- input . val ( text . replace ( identifier , phrase ) ) ;
1859
- input . caret ( pos + phrase . length ) ;
1853
+ replaceValueWithSuggestion ( input , text , identifier , ui . item . phrase ) ;
1860
1854
1861
1855
event . preventDefault ( ) ; // to prevent the movement of the caret to the end
1862
1856
} ,
@@ -1903,6 +1897,13 @@ function getAutocompleteMenuData(input, field) {
1903
1897
}
1904
1898
}
1905
1899
1900
+ function replaceValueWithSuggestion ( input , queryText , identifier , suggestion ) {
1901
+ var pos = queryText . indexOf ( identifier ) ;
1902
+ var phrase = escapeLuceneCharacters ( suggestion ) ;
1903
+ input . val ( queryText . replace ( identifier , phrase ) ) ;
1904
+ input . caret ( pos + phrase . length ) ;
1905
+ }
1906
+
1906
1907
function showError ( errorText , errorElem ) {
1907
1908
var parent = errorElem . parent ( ) ;
1908
1909
0 commit comments