diff --git a/lib/BridgeCard.php b/lib/BridgeCard.php
index 7b7787c5..edde6e70 100644
--- a/lib/BridgeCard.php
+++ b/lib/BridgeCard.php
@@ -251,7 +251,7 @@ final class BridgeCard
$attributes = self::getInputAttributes($entry);
$fieldsDisplayString = '';
- foreach($entry['fields_name_used_for_display'] as $index => $field) {
+ foreach ($entry['fields_name_used_for_display'] as $index => $field) {
if ($index === 0) {
$fieldsDisplayString = 'option.' . $field;
} else {
@@ -260,7 +260,7 @@ final class BridgeCard
}
$fieldsValueString = '';
- foreach($entry['fields_name_used_as_value'] as $index => $field) {
+ foreach ($entry['fields_name_used_as_value'] as $index => $field) {
if ($index === 0) {
$fieldsValueString = 'option.' . $field;
} else {
@@ -268,64 +268,65 @@ final class BridgeCard
}
}
- $list = sprintf('' . "\n",
- $attributes,
- $id,
- $name,
- $id,
- $id,
- Configuration::getConfig('proxy', 'url') ?: 'https://cors-anywhere.herokuapp.com/',
- $entry['ajax_route'],
- $fieldsDisplayString,
- $fieldsValueString,
+ xhr.onload = function () {
+ if (xhr.status === 200) {
+ // Parse the response and update the datalist
+ datalist.innerHTML = \'\'; // Clear existing options
+ const options = JSON.parse(xhr.responseText); // Assuming JSON response
+ options.forEach(option => {
+ const opt = document.createElement(\'option\');
+
+ opt.innerHTML = %s; // the displayed value
+ opt.value = %s; // the value
+ datalist.appendChild(opt);
+ });
+ // set himself enabled when the request is done
+ inputElement.value = \'\';
+ inputElement.disabled = false;
+ } else {
+ errorElement.innerHTML = \'failed fetching data\';
+ inputElement.value = \'\';
+ inputElement.disabled = false;
+ }
+ };
+ xhr.send();
+ }
+ " />' . "\n",
+ $attributes,
+ $id,
+ $name,
+ $id,
+ $id,
+ Configuration::getConfig('proxy', 'url') ?: 'https://cors-anywhere.herokuapp.com/',
+ $entry['ajax_route'],
+ $fieldsDisplayString,
+ $fieldsValueString,
);
$list .= sprintf('' . "\n", $id);
$list .= sprintf('