【发布时间】:2013-08-03 18:44:08
【问题描述】:
我正在使用 typeahead.js 将产品 ID 分配给隐藏的 html 表单字段。这在匹配时非常有用:
$('.products_tt .typeahead').typeahead
name: 'products_tt',
prefetch:
url: '/products.json',
ttl: 60 * 5e3
template: '<p><strong>{{value}}</strong> – {{year}}</p>',
engine: Hogan
$('.products_tt .typeahead').on "typeahead:selected typeahead:autocompleted", (e,datum) ->
$('#disk_file_product_id').val(datum.id)
当输入字段为空白时,我清除隐藏字段:
$('.products_tt .typeahead').blur ->
if $(this).val().length == 0
$('#disk_file_product_id').val("")
但是当在输入字段中输入文本但没有匹配时,我还需要清除隐藏字段。
我的 Java/Coffeescript 技能很弱,所以不知道该怎么做?!?
【问题讨论】:
标签: javascript jquery ruby-on-rails coffeescript typeahead.js