28 lines
807 B
JavaScript
28 lines
807 B
JavaScript
const $ = require('jquery');
|
|
const Choices = require('choices.js');
|
|
|
|
module.exports = function() {
|
|
$('*[data-rest-choices]').each(function(key, item) {
|
|
const url = $(this).attr('data-rest-choices');
|
|
|
|
new Choices(item, {
|
|
searchPlaceholderValue: 'Chercher',
|
|
}).setChoices(function() {
|
|
return fetch(url)
|
|
.then(function(response) {
|
|
return response.json();
|
|
})
|
|
.then(function(data) {
|
|
return data.map(function(d) {
|
|
return {
|
|
label: d.label,
|
|
value: d.value
|
|
};
|
|
});
|
|
});
|
|
})
|
|
.then(function(instance) {
|
|
});
|
|
})
|
|
};
|