Skip to content
Snippets Groups Projects

Draft: feat: replace select2 with accessible selectize

Closed Jonáš Herec requested to merge feat-accesibility into main
django.jQuery(function () {
django.jQuery("select.address").each(function () {
const select = django.jQuery(this);
const defaultValue = select.data("select2-default-value");
select.append('<option value="' + defaultValue + '">' + defaultValue + '</option>');
});
<script>
django.jQuery(function () {
django.jQuery("select.address").each(function () {
const select = django.jQuery(this);
const defaultValue = select.data("selectize-default-value");
const option = new Option(defaultValue, defaultValue, true, true);
select.append(option);
});
const apiKey = django.jQuery("select.address").data("select2-api-key");
const categories = django.jQuery("select.address").data("select2-filter-categories");
const apiKey = django.jQuery("select.address").data("selectize-api-key");
const categories = django.jQuery("select.address").data("selectize-filter-categories");
django.jQuery("select.address").selectize({
create: false,
valueField: 'id',
labelField: 'text',
searchField: 'text',
minimumInputLength: 5,
allowClear: true,
placeholder: "---",
load: function (query, callback) {
django.jQuery.ajax({
url: "https://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer/suggest",
dataType: "json",
data: {
django.jQuery("select.address").selectize({
create: false,
persist: false,
openOnFocus: true,
valueField: 'text',
labelField: 'text',
searchField: 'text',
minimumInputLength: 5,
allowClear: true,
placeholder: "---",
load: function(query, callback) {
var data = {
text: query,
category: categories,
token: apiKey,
f: "json",
},
success: function (data) {
const results = data.suggestions.map(function (suggestion) {
return {
};
django.jQuery.ajax({
url: "https://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer/suggest",
dataType: "json",
data: data,
success: function(data) {
callback(data.suggestions.map((suggestion) => ({
text: suggestion.text,
id: suggestion.text,
};
});
callback(results);
},
});
},
})));
}
});
},
});
});
});
</script>
Loading