typeahead.js icon indicating copy to clipboard operation
typeahead.js copied to clipboard

Unclear duplication (in the form of plain text) on input

Open ahmadkeren opened this issue 2 years ago • 1 comments

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

ahmadkeren avatar Jul 12 '22 09:07 ahmadkeren

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.

OvenBoy avatar May 14 '24 16:05 OvenBoy