jQuery Tokeninput add if not exists

前端 未结 8 732
野的像风
野的像风 2021-02-05 09:07

I am in the process of writing a script that builds upon user input,

I have some fields that its values need to be quired from the database,

and if no entry fo

8条回答
  •  逝去的感伤
    2021-02-05 09:15

    When you enable tokenInput on a field,

    $(selector).tokenInput(url, ...
    

    that url is where tokenInput sends search queries. It points to a script which returns suggestions based on database entries matching the search query. What you want is to have that script add another suggestion to the list for that case when nothing in your database matches the search query. How to do this depends very much on the script.

    Because you tagged your question with php, I'm guessing the url points to a php script which returns a JSON object full of suggestions. In that case, modify the php script so that it adds a new suggestion to the list:

    "{id: " . $idForThisNewSuggestion . ", name: \"" . $searchQueryString . " (new suggestion)\"}"
    

提交回复
热议问题