client/general: handle spaces in autocomplete

This commit is contained in:
rr- 2016-07-03 19:37:10 +02:00
parent 7ae2778e48
commit abd8e9e89c
4 changed files with 7 additions and 5 deletions

View file

@ -3,7 +3,7 @@
<div class='input'> <div class='input'>
<ul> <ul>
<li class='names'> <li class='names'>
<%= ctx.makeTextInput({text: 'Names', value: ctx.tag.names.join(' '), required: true, readonly: !ctx.canEditNames, pattern: ctx.tagNamesPattern}) %> <%= ctx.makeTextInput({text: 'Names', value: ctx.tag.names.join(' '), required: true, readonly: !ctx.canEditNames}) %>
</li> </li>
<li class='category'> <li class='category'>
<%= ctx.makeSelect({text: 'Category', keyValues: ctx.categories, selectedKey: ctx.tag.category, required: true, readonly: !ctx.canEditCategory}) %> <%= ctx.makeSelect({text: 'Category', keyValues: ctx.categories, selectedKey: ctx.tag.category, required: true, readonly: !ctx.canEditCategory}) %>

View file

@ -30,6 +30,7 @@ class AutoCompleteControl {
Object.assign(this._options, { Object.assign(this._options, {
verticalShift: 2, verticalShift: 2,
source: null, source: null,
addSpace: false,
maxResults: 15, maxResults: 15,
getTextToFind: () => { getTextToFind: () => {
const value = sourceInputNode.value; const value = sourceInputNode.value;
@ -50,6 +51,9 @@ class AutoCompleteControl {
this._results[this._activeResult].value + this._results[this._activeResult].value +
' ' + ' ' +
suffix.trimLeft(); suffix.trimLeft();
if (!this._options.addSpace) {
sourceInputNode.value = sourceInputNode.value.trim();
}
sourceInputNode.focus(); sourceInputNode.focus();
}, },
delete: text => { delete: text => {

View file

@ -10,9 +10,7 @@ class TagAutoCompleteControl extends AutoCompleteControl {
const caseSensitive = false; const caseSensitive = false;
const minLengthForPartialSearch = 3; const minLengthForPartialSearch = 3;
if (!options) { options = Object.assign({}, options);
options = {};
}
options.getMatches = text => { options.getMatches = text => {
const transform = caseSensitive ? const transform = caseSensitive ?

View file

@ -17,7 +17,7 @@ class PostsHeaderView {
views.replaceContent(this._hostNode, template(ctx)); views.replaceContent(this._hostNode, template(ctx));
if (this._queryInputNode) { if (this._queryInputNode) {
new TagAutoCompleteControl(this._queryInputNode); new TagAutoCompleteControl(this._queryInputNode, {addSpace: true});
} }
keyboard.bind('q', () => { keyboard.bind('q', () => {