Skip to content

Commit

Permalink
fix: bug autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaslabbe committed Nov 18, 2016
1 parent 9c83561 commit 727f6a5
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions src/server/public/scripts/modules/EditorAutocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ export default class EditorAutocomplete {
splittedDiplay.shift()

variables[i].value = splittedDiplay.join('.')
}else {
trueJson = []
}
})
}
Expand All @@ -228,31 +230,29 @@ export default class EditorAutocomplete {
var j = 0
Array.prototype.forEach.call(trueJson, (item) => {
var sourceVal = ""
var replace = []
var replace = ""
var sourceDisplay = display
if (Object.prototype.toString.call(item) === '[object Object]') {
try {
var sourceValCheck = eval('item.' + variables[i].value)
if (sourceValCheck.indexOf(val) > -1) {
replace.push({key: variables[i].replace, value: sourceValCheck})
sourceVal = item
sourceDisplay = sourceValCheck
}
replace = {key: variables[i].replace, value: sourceValCheck}
sourceVal = item
sourceDisplay = sourceValCheck
}catch(e) {
console.log(e)
}
}else {
if (item.indexOf(val) > -1) {
sourceVal = item
}
sourceVal = item
}
if (sourceVal != "") {
if (deepValues[j] == null) {
deepValues[j] = {
replace: replace,
replace: [replace],
value: typeof sourceVal == 'string' ? [sourceVal] : sourceVal,
display: (display == null || display == "null") ? sourceVal : display
}
}else {
deepValues[j].replace.push(replace)
}
j++
}
Expand All @@ -267,16 +267,18 @@ export default class EditorAutocomplete {
Array.prototype.forEach.call(item.replace, (replace) => {
displayName = displayName.replace(new RegExp(replace.key, 'g'), replace.value)
})
var div = document.createElement('div')
div.addEventListener('mousedown', this._handleSelectValue)
div.setAttribute('data-value', JSON.stringify(item.value))
div.setAttribute('data-display', displayName)
if(first) {
div.classList.add('selected')
if (displayName.toLowerCase().indexOf(val.toLowerCase()) > -1) {
var div = document.createElement('div')
div.addEventListener('mousedown', this._handleSelectValue)
div.setAttribute('data-value', JSON.stringify(item.value))
div.setAttribute('data-display', displayName)
if(first) {
div.classList.add('selected')
}
first = false
div.innerHTML = displayName.replace(new RegExp(`(${val})`, 'i'), `<span class="select">$1</span>`)
this._divWrapper.appendChild(div)
}
first = false
div.innerHTML = displayName.replace(new RegExp(`(${val})`, 'i'), `<span class="select">$1</span>`)
this._divWrapper.appendChild(div)
})
}

Expand Down Expand Up @@ -317,7 +319,9 @@ export default class EditorAutocomplete {
var match
while (match = /\{\{(.*?)\}\}/.exec(dataVal)) {
var selector = target.form.querySelector('[data-id="' + match[1] + '"]')
if(selector != null) dataVal = dataVal.replace('{{' + match[1] + '}}', selector.value)
if(selector != null) {
dataVal = dataVal.replace('{{' + match[1] + '}}', selector.value)
}
}
}

Expand Down

0 comments on commit 727f6a5

Please sign in to comment.