-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
38382da
commit 29c6669
Showing
3 changed files
with
36 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
if(window.Choices) | ||
{ | ||
document.addEventListener('DOMContentLoaded', function() { | ||
const elements = document.querySelectorAll('[data-choices="1"]'); | ||
elements.forEach(element => { | ||
const removeItemButton = element.getAttribute('data-choices-removeItemButton') != 0; | ||
const maxItemCount = element.getAttribute('data-choices-maxItemCount') || -1; | ||
const choicesElement = new Choices(element, { | ||
removeItemButton: removeItemButton, | ||
maxItemCount: maxItemCount | ||
}); | ||
const dataUrl = element.getAttribute('data-choices-url'); | ||
if (dataUrl) { | ||
choicesElement.passedElement.element.addEventListener( | ||
'search', async (event) => { | ||
try { | ||
const items = await fetch(`${dataUrl}?search=${event.detail.value}&autocomplete=1`); | ||
const data = await items.json(); | ||
// Clear existing choices | ||
choicesElement.clearChoices(); | ||
|
||
// Set new choices | ||
choicesElement.setChoices(data, 'value', 'label', true); | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
}); | ||
} | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,4 +22,4 @@ | |
<?php if ($options['wrapper'] !== false) { ?> | ||
</div> | ||
<?php } ?> | ||
<?php } ?> | ||
<?php } ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters