text_field_with_auto_complete inside form_for

后端 未结 5 1760
既然无缘
既然无缘 2021-02-10 09:25

Simple question really - how do I use text_field_with_auto_complete inside a form_for block?

I\'ve tried doing f.text_field_with_auto_com

5条回答
  •  闹比i
    闹比i (楼主)
    2021-02-10 09:44

    I personally use this:

    <%= f.text_field :name, :autocomplete => "off" %>

    And add the auto-generated Javascript and CSS manually. Here's the Javascript:

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

    and here's the 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;
    }
    

提交回复
热议问题