typeahead.js
typeahead.js copied to clipboard
Unclear duplication (in the form of plain text) on input
Why is it that every time I finish typing in tagsinput (focus out of the text area), duplicates always appear in plain text on the form as shown in the image/video below.
https://user-images.githubusercontent.com/49072140/178454846-8b70f501-f953-430b-8783-d91c70b84407.mov
I know this is 2 years late - but here is my fix.
container.addEventListener('keypress', event => {
if (event.key === 'Enter') {
if (event.target.nodeName !== 'SPAN') {
event.preventDefault()
if (event.target.value.length === 0 || !event.target.value.trim()) return false
//do insert tag
});
} else {
//do delete tag
}
event.target.value = ' ' //reset target value (this probably isn't needed)
$('.typeahead').typeahead('val', ' ') //"reset" typeahead val
}
})
In the docs, there is an API function that allows for the typeahead to be set to any value.
At least in my case, this line $('.typeahead').typeahead('val', ' ')
inside the check for the enter key also works for the de-focusing issue as well.