Skip to content

Commit

Permalink
Add autocomplete for set codes
Browse files Browse the repository at this point in the history
  • Loading branch information
ldeluigi committed Mar 3, 2023
1 parent 6ec7d59 commit 2c595ce
Showing 1 changed file with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{% extends "admin/change_form.html" %}

{% block extrahead %}
{{ block.super }}
{% include 'admin/spellbook/includes/jquery_imports.html' %}
{% endblock %}

{% block admin_change_form_document_ready %}
{{ block.super }}
{% if original.key == 'featured_set_codes' %}
<script>
const scryfallSets = [];
django.jQuery.getJSON(
'https://api.scryfall.com/sets',
function (data) {
scryfallSets.push(...data.data.map(e => e.code));
});
django.jQuery('#id_value').autocomplete({
source: function (request, response) {
response(django.jQuery.ui.autocomplete
.filter(scryfallSets, request.term.replace(/^.+\,\s*/, ''))
.slice(0, 10));
},
minLength: 0,
delay: 0,
autoFocus: true,
select: function (event, ui) {
const item = django.jQuery(event.target);
const current = item.val().replace(/[^\,\s]+$/, '');
item.val(current + ui.item.value);
return false;
},
focus: function (event, ui) {
return false;
},
});
</script>
{% endif %}
{% endblock %}

0 comments on commit 2c595ce

Please sign in to comment.