Any idea not to select the name that is already chosen in token input?

…衆ロ難τιáo~ 提交于 2019-12-24 10:11:28

问题


Is there any idea not to select the name that is already chosen in token input? For example In first I select mango when I search for m. Next time again when I search for m Mango should not be displayed as mango is already chosen. Is there any idea?

 <%= f.text_field :plan_tokens, data: {load: @customer.plans} %>

I have my js like this jQuery ->

 $('#customer_plan_tokens').tokenInput '/plans.json'
    theme: 'facebook'
    prePopulate: $('#customer_plan_tokens').data('load')

where to put preventDuplicates:true. I did try but error arise!

I study this from

http://railscasts.com/episodes/258-token-fields

http://railscasts.com/episodes/258-token-fields-revised



回答1:


When you initialize tokeninput in your JavaScript, you can add preventDuplicates: true and this will prevent duplicates from being selected, but they'll still be shown in the results (demo).

So something like:

$(...).tokenInput("url", { preventDuplicates: true, otherOptionsHere });

If you don't want them shown at all, it would probably be possible to write some code for the onResult callback that checks the value of the field and removes the ones that are already there.

edit: since you use CoffeeScript, try

$('#customer_plan_tokens').tokenInput '/plans.json'
   theme: 'facebook'
   prePopulate: $('#customer_plan_tokens').data('load')
   preventDuplicates: true


来源:https://stackoverflow.com/questions/12154136/any-idea-not-to-select-the-name-that-is-already-chosen-in-token-input

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!