Twitter bootstrap typeahead multiple values?

前端 未结 5 1350
梦如初夏
梦如初夏 2020-11-29 18:56

I\'m using Twitter Bootstrap with Jquery. I want to use the TYPEAHEAD function for a textarea, which I got to work super easily. But I also need it to allow mul

5条回答
  •  萌比男神i
    2020-11-29 19:13

    I'm late to the party, but this is what I came up with for Bootstrap v4. It also requires d3 (as I am not so familiar with jQuery).

    You can see an example running at http://sumneuron.gitlab.io/multitags/

    It has some useful features, is written in a clearly, and should get anyone who finds this off to a good start. Especially if you were ever curious as to how tagging is implemented.

    Code is available at https://gitlab.com/SumNeuron/multitags/pipelines

    The logic is roughly as follows:

    if keydown in [enter, ","]:
        // logic of function "doneTyping" 
        text = parse(text) // get text from textarea and grab latest value
        if text is valid:
            renderTag(text) // put the text in a tag element
            updateHiddenForm(text) // update the hidden form to include the tag
        else:
            notifyUserOfInvalidTag(text) // alert user
    else:
        // logic of function "stillTyping" 
        suggest = bloodhoundSearch(text) // use twitter typeahead
        updateSuggestionBox(suggest) // display results from typeahead
    

提交回复
热议问题