简体   繁体   中英

How to add data-trigger attribute in select_tag rails 5

I am trying to add the data-trigger attribute to my form, but everytime I add data-trigger I get an syntax error. I already tried different syntax with column and brackets and with an equal sign, but nothing seems to work.

Here is my view:

<div class="container">

 <div class="s003">
   <%= search_form_for @search, url: search_path, remote: true do |f| %>
      <div class="inner-form">
        <div class="input-field first-wrap">
          <div class="input-select">
            <%= f.select :wine_type_gteq, [["Riesling", "Riesling"], ["Gewürztraminer", "Gewürztraminer"], ["Chardonnay", "Chardonnay"], ["Sauvignon Blanc", "Sauvignon Blanc"],
            ["Weißburgunder", "Weißburgunder"], ["Grauburgunder", "Grauburgunder"], ["Spätburgunder", "Spätburgunder"], ["Tempranillo", "Tempranillo"], ["Pinotage", "Pinotage"], ["Shiraz", "Shiraz"], ["Cabernet Sauvignon", "Cabernet Sauvignon"],
            ["Merlot", "Merlot"], ["Syrah", "Syrah"], ["Pinot Noir", "Pinot Noir"], ["Cabernet Franc", "Cabernet Franc"], ["Malbec", "Malbec"], ["Garnacha", "Garnacha"], ["Sangiovese", "Sangiovese"]], id: "wine_type", prompt: "Select..." %>
          </div>
        </div>
        <div class="input-field second-wrap">
          <%= text_field_tag :search, params[:search], placeholder: "Wein...", class: "form-control", id: "autolocation" %>
        </div>
        <div class="input-field third-wrap">
          <button class="btn-search">
            <%= submit_tag "Suchen", style: "color:white" %>
          </button>
        </div>
      </div>
      <% end %>
  </div>
</div>
<script>
  const choices = new Choices('[data-trigger]',
  {
    searchEnabled: false,
    itemSelectText: '',
  });

Want I want to achieve:

<div class="input-select">
              <select data-trigger="" name="choices-single-defaul">
                <option>Category</option>
                <option>Category</option>
                <option>Category</option>
                <option>Category</option>
                <option>Category</option>
                <option>Category</option>
                <option>Category</option>
                <option>Category</option>
              </select>
            </div>
<%= f.select :wine_type_gteq, [["Riesling", "Riesling"],...], { prompt: "Select..." }, id: "wine_type", data: { trigger: 'something' } %>

文献

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM