From 6feb466240e0465733ed47566d350829fa23678b Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Wed, 2 Mar 2016 16:09:52 +0000 Subject: [PATCH] Autocomplete: only replace input when a prefix matches (fixes #2753) Previously, if the top match for "Smi" was "John Smith", the contents of the field would be changed to "Smi[n Smith]" (where square brackets indicate selection). On top of this, if you then type the fourth letter ("n"), the input becomes "Smin", which is not what you typed. This preserves the "happy path" for replacing the field contents if there is a prefix match, but without making the field unusable if there's an infix match. --- source/UI/js/Form/Input.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/UI/js/Form/Input.js b/source/UI/js/Form/Input.js index 3af912b..3708a91 100644 --- a/source/UI/js/Form/Input.js +++ b/source/UI/js/Form/Input.js @@ -431,8 +431,11 @@ Ox.Input = function(options, self) { value; if (values[0]) { - if (self.options.autocompleteReplace) { + if (self.options.autocompleteReplace && + Ox.startsWith(values[0].toLowerCase(), + self.options.value.toLowerCase())) { newValue = values[0]; + selected = 0; } else { newValue = self.options.value; } @@ -456,7 +459,6 @@ Ox.Input = function(options, self) { } else { cursor(pos); } - selected = 0; } if (self.options.autocompleteSelect) { -- 2.5.0