任何想法不选择已经在令牌输入中选择的名称? [英] Any idea not to select the name that is already chosen in token input?
问题描述
有没有想法不选择已经在令牌输入中选择的名称?例如在第一个我选择芒果,当我搜索m。下次再次当我搜索m芒果不应该显示为芒果已经选择。有什么想法吗?
<%= f.text_field:plan_tokens,data:{load:@ customer.plans}% >
我有我的js喜欢这个
jQuery - >
$('#customer_plan_tokens')。tokenInput'/plans.json'
theme:'facebook'
prePopulate:$(' customer_plan_tokens')。data('load')
其中放置preventDuplicates:true。
http://railscasts.com/episodes/258-token-fields-revised
在JavaScript中初始化tokeninput时, code> preventDuplicates:true ,这将防止选择重复项,但仍会显示在结果中( 像这样: 如果你不想显示它们,可能会写一些代码 编辑:由于您使用CoffeeScript,请尝试 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? I have my js like this
jQuery -> 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
$(...)。tokenInput(url,{preventDuplicates:true,otherOptionsHere});
onResult
回调,用于检查字段的值并删除已存在的字段。
$('#customer_plan_tokens')。tokenInput'/plans.json '
pre>
theme:'facebook'
prePopulate:$('#customer_plan_tokens')。data('load')
preventDuplicates:true
<%= f.text_field :plan_tokens, data: {load: @customer.plans} %>
$('#customer_plan_tokens').tokenInput '/plans.json'
theme: 'facebook'
prePopulate: $('#customer_plan_tokens').data('load')
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
这篇关于任何想法不选择已经在令牌输入中选择的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!