Skip to content

Commit

Permalink
Use datalist instead of jquery-ui/autocomplete
Browse files Browse the repository at this point in the history
Replaces jquery-ui/autocomplete, which is only used in the product
properties page, with the html5 <datalist> element.

Browser support for datalist is patchy (notably no safari), but it is
entirely fine for this page not to have autocompletion.

We had apparently already decided that the number of properties is low
enough that they can be just dumped on the page as json, so we might as
well dump them on the page as HTML.
  • Loading branch information
jhawthorn committed Jan 18, 2018
1 parent 15e2dee commit d5e2e54
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<% end %>
</td>
<td class='property_name'>
<%= f.text_field :property_name, class: 'autocomplete' %>
<%= f.text_field :property_name, list: 'properties' %>
</td>
<td class='value'>
<%= f.text_field :value %>
Expand Down
13 changes: 3 additions & 10 deletions backend/app/views/spree/admin/product_properties/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,6 @@
<% end %>
<% end %>

<%= javascript_tag do -%>
var properties = <%= raw(@properties.to_json) %>;
$('#product_properties, #variant_property_values').on('keydown', 'input.autocomplete', function() {
already_auto_completed = $(this).is('ac_input');
if (!already_auto_completed) {
$(this).autocomplete({source: properties});
$(this).focus();
}
});
<% end -%>
<datalist id="properties">
<%= safe_join @properties.map { |name| tag(:option, value: name) } %>
</datalist>

0 comments on commit d5e2e54

Please sign in to comment.