任何想法不选择已经在令牌输入中选择的名称? [英] Any idea not to select the name that is already chosen in token input?

查看:273
本文介绍了任何想法不选择已经在令牌输入中选择的名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有想法不选择已经在令牌输入中选择的名称?例如在第一个我选择芒果,当我搜索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。



railscasts.com/episodes/258-token-fieldsrel =nofollow> http://railscasts.com/episodes/258-token-fields



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





解决方案

在JavaScript中初始化tokeninput时, code> preventDuplicates:true ,这将防止选择重复项,但仍会显示在结果中(

像这样:

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

如果你不想显示它们,可能会写一些代码 onResult 回调,用于检查字段的值并删除已存在的字段。



编辑:由于您使用CoffeeScript,请尝试

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

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


解决方案

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆