Skip to content

Commit

Permalink
fixes in KMP done first in AMP
Browse files Browse the repository at this point in the history
  • Loading branch information
jhandel committed Sep 6, 2024
1 parent 37be253 commit 8cd1c41
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
18 changes: 13 additions & 5 deletions app/assets/js/controllers/auto-complete-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class AutoComplete extends Controller {

initSelectionValueChanged() {
if (this._datalistLoaded) {
if (this.initSelectionValue == null) {
if (this.initSelectionValue == null || !this.initSelectionValue.hasOwnProperty("value")) {
return;
}
let newOption = this.initSelectionValue;
Expand All @@ -166,8 +166,11 @@ class AutoComplete extends Controller {
this.value = newOption.value;
}
} else {
this.hiddenTarget.value = this.initSelectionValue.value;
this.inputTarget.value = this.initSelectionValue.text;
//check if there is a value key in the initSelectionValue object
if (this.initSelectionValue.hasOwnProperty("value")) {
this.hiddenTarget.value = this.initSelectionValue.value;
this.inputTarget.value = this.initSelectionValue.text;
}
}
}

Expand Down Expand Up @@ -429,9 +432,14 @@ class AutoComplete extends Controller {
}
itemHtml.setAttribute("role", "option")
itemHtml.setAttribute("aria-selected", "false")
itemHtml.textContent = item.text;

//add a span around matching string to highlight it
itemHtml.innerHTML = itemHtml.innerHTML.replace(new RegExp(query, 'gi'), match => `<span class="text-primary">${match}</span>`);
if (query != "") {
let filteredOptions = item.text;
itemHtml.innerHTML = filteredOptions.replace(new RegExp(query, 'gi'), match => `<span class="text-primary">${match}</span>`);
} else {
itemHtml.innerHTML = item.text;
}
this.resultsTarget.appendChild(itemHtml);
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/View/Helper/KmpHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function comboBoxControl($Form, $inputField, $resultField, $data, $label,
"data-ac-target" => "input",
"container" => ["style" => "margin:0 !important;",]
]);
echo "<ul data-ac-target='results' class='list-group z-3 col-12 position-absolute auto-complete-list'></ul></div>";
echo "<ul data-ac-target='results' class='list-group z-3 col-12 position-absolute auto-complete-list' hidden='hidden' ></ul></div>";
}

public function autoCompleteControl($Form, $inputField, $resultField, $url, $label, $required, $allowOtherValues, $minLength, $additionalAttrs,)
Expand All @@ -126,7 +126,7 @@ public function autoCompleteControl($Form, $inputField, $resultField, $url, $lab
"data-ac-target" => "input",
"container" => ["style" => "margin:0 !important;",]
]);
echo "<ul data-ac-target='results' class='list-group z-3 col-12 position-absolute auto-complete-list'></ul></div>";
echo "<ul data-ac-target='results' class='list-group z-3 col-12 position-absolute auto-complete-list' hidden='hidden' ></ul></div>";
}
/**
* Returns a boolean icon
Expand Down

0 comments on commit 8cd1c41

Please sign in to comment.