form_for 内的 text_field_with_auto_complete

2023-12-21

真的很简单的问题 - 我如何使用text_field_with_auto_complete里面一个form_for block?

我试过做f.text_field_with_auto_complete但这会产生错误,只需使用text_field_with_auto_complete其本身似乎没有做任何事情。

我在这里错过了什么吗?


我个人使用这个:

<%= f.text_field :name, :autocomplete => "off" %><div class="auto_complete" id="customer_name_auto_complete"></div>

并手动添加自动生成的 Javascript 和 CSS。这是 JavaScript:

new Ajax.Autocompleter('customer_name', 'customer_name_auto_complete', '/customers/auto_complete_for_customer_name', {
    method:'get',
    paramName:'customer[name]',
    minChars: 3
});

这是 CSS:

div.auto_complete {
  width: 350px;
  background: #fff;
}

div.auto_complete ul {
  border:1px solid #888;
  margin:0;
  padding:0;
  width:100%;
  list-style-type:none;
}

div.auto_complete ul li {
  margin:0;
  padding:3px;
}

div.auto_complete ul li.selected {
  background-color: #ffb;
}

div.auto_complete ul strong.highlight {
  color: #800;
  margin:0;
  padding:0;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

form_for 内的 text_field_with_auto_complete 的相关文章

随机推荐