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.
This commit is contained in:
parent
eaa4183e60
commit
3637b70244
1 changed files with 4 additions and 2 deletions
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue