我创建了一个表单,用户可以在其中创建配置文件,并使用jquery tokenInput从自动完成令牌字段中选择关键字。问题是,只要我对文本字段调用.tokenInput(),提交表单时就不会发送其中的文本。我使用的是mongodb。下面是我的配置文件类:
class Profile
include Mongoid::Document
include Mongoid::Timestamps
field :status, type: String
field :displayname, type: String
field :city, type: String
field :country, type: String
field "_id", type: String, default: ->{ displayname.to_s.parameterize}
attr_accessible :user_tags, :displayname, :city, :country, :tagg_tokens
attr_reader :tagg_tokens
belongs_to :user
end我的coffeescript文件:
$("#profile_tagg_tokens").tokenInput '/taggs.json‘主题:'facebook’
我的表单:
=f.text_field :tagg_tokens以前有没有人遇到过这个问题?感谢您的帮助
发布于 2013-02-18 21:27:18
默认情况下,令牌只生成一个简单的html,因此令牌的任何部分都不会随表单一起发送。我建议您考虑使用其中一个回调函数来添加隐藏输入
onAdd: function (item) { $('form').append('<input type="hidden" value=' + item.id + '>' }我还没有测试过这个,但是你应该明白了。您还可以使用另一个名为tokenFormatter的选项(也未经过测试)
tokenFormatter: function(item){ return '<li><p>' + item.propertyToSearch + '</p><input type="hidden" value=' + item.id + '></li>' } https://stackoverflow.com/questions/14936544
复制相似问题