SpeciesFileGroup/taxonworks

View on GitHub
app/views/workbench/elements/forms/_ajax_select.html.erb

Summary

Maintainability
Test Coverage
<%# Configuration for all pickers  -%>
<% css_class ||= 'ajaxPicker' -%>
<% action ||= 'autocomplete'.html_safe -%>
<% fields_for_object ||= nil -%>
<% object_name ||= controller.humanize.downcase.singularize.html_safe.gsub(/\//, '') -%>
<% send_select ||= false %>
<% autofocus ||= nil %>

<% url = url_for({
  controller: controller,
  action: action,
  tag_id: tag_id,
  method: "#{object}[#{method}]",
  escape: false}) -%>

<input autocomplete="off"
       title="Find and select a <%= object_name -%>. You must click or tab off a row to choose the item."
       placeholder="Select a <%= object_name -%>"
       class="mx-autocomplete <%= css_class -%> mousetrap"
       id="<%= tag_id %>"
       <%= ('autofocus="autofocus"').html_safe if !autofocus.nil? -%>
       data-send-select="<%= send_select %>"
       data-mx-autocomplete-url="<%= url %>"
       data-mx-method="<%= "#{object}[#{method}]" %>"
       <%= ((size ||= nil).nil? ? 'style="width:98%;"' : "size=\"#{size}\"").html_safe -%>
       type="text"
       value="<%= display -%>"
       />

<% if fields_for_object -%>
  <%= fields_for_object.hidden_field(method, id: "#{tag_id}_hidden_value" ) -%>
<% else %>
  <%= hidden_field(object, method, id: "#{tag_id}_hidden_value") -%>
<% end %>