diff --git a/src/Views/Home/Assets.cshtml b/src/Views/Home/Assets.cshtml
index 4a20bd6..79ee670 100644
--- a/src/Views/Home/Assets.cshtml
+++ b/src/Views/Home/Assets.cshtml
@@ -489,13 +489,16 @@ document.addEventListener('DOMContentLoaded', () => {
updateAttributesContainer.innerHTML = '';
updateForm.reset();
- const locationSelect = updateForm.querySelector('#updateLocationSelect');
- await loadLocationsIntoSelect(locationSelect);
try {
const response = await fetch(`/Assets/Get?cn=${assetId}`);
const responseJson = await response.json();
const asset = responseJson.assetsModel;
+ const locationSelect = updateForm.querySelector('#updateLocationSelect');
+ await loadLocationsIntoSelect(locationSelect, asset.Location);
+ const usersSelect = updateForm.querySelector('#updateUsersSelect');
+ await loadUsersIntoSelect(usersSelect, asset.Owner);
+
for (const [key, value] of Object.entries(asset)) {
const input = updateForm.querySelector(`[name="${key}"]`);
if (input) input.value = value;
diff --git a/src/wwwroot/js/site.js b/src/wwwroot/js/site.js
index dfad9b8..4604645 100644
--- a/src/wwwroot/js/site.js
+++ b/src/wwwroot/js/site.js
@@ -123,18 +123,35 @@ async function loadLocationsIntoSelect(selectElement, selectedValue = null) {
const response = await fetch('/Locations/Index');
const locations = await response.json();
- selectElement.innerHTML = ``;
+ const ts = selectElement.tomselect;
+
+ if (!ts) {
+ selectElement.innerHTML = ``;
+ locations.forEach(loc => {
+ const option = document.createElement('option');
+ option.value = loc.location;
+ option.textContent = loc.location;
+ if (selectedValue && selectedValue === loc.location) {
+ option.selected = true;
+ }
+ selectElement.appendChild(option);
+ });
+ return;
+ }
+
+ ts.clearOptions();
+ ts.addOption(locations.map(loc => ({
+ value: loc.location,
+ text: loc.location
+ })));
+ ts.refreshOptions(false);
+
+ if (selectedValue) {
+ ts.setValue(selectedValue);
+ } else {
+ ts.clear(true);
+ }
- locations.forEach(loc => {
- const text = `${loc.location}`;
- const option = document.createElement('option');
- option.value = loc.location;
- option.textContent = text;
- if (selectedValue && selectedValue === loc.location) {
- option.selected = true;
- }
- selectElement.appendChild(option);
- });
} catch (err) {
console.error('Error loading locations:', err);
showToast(appTranslations.errorLoadingLocations, 'danger');
@@ -146,20 +163,25 @@ async function loadUsersIntoSelect(selectElement, selectedValue = null) {
const response = await fetch('/Users/Index?Cn=false&Sn=false&Title=false&Description=false&JpegPhoto=false&UserPassword=false');
const users = await response.json();
- selectElement.innerHTML = ``;
+ const ts = selectElement.tomselect;
+ if (!ts) {
+ selectElement.innerHTML = ``;
+ users.forEach(u => {
+ const opt = document.createElement('option');
+ opt.value = u.uid;
+ opt.textContent = u.uid;
+ selectElement.appendChild(opt);
+ });
+ return;
+ }
- users.forEach(usr => {
- const text = usr.uid;
- const option = document.createElement('option');
- option.value = usr.uid;
- option.textContent = text;
- if (selectedValue && selectedValue === usr.uid) {
- option.selected = true;
- }
- selectElement.appendChild(option);
- });
+ ts.clearOptions();
+ ts.addOption(users.map(u => ({ value: u.uid, text: u.uid })));
+ ts.refreshOptions(false);
+
+ if (selectedValue) ts.setValue(selectedValue);
} catch (err) {
console.error('Error loading users:', err);
showToast(appTranslations.errorLoadingUsers, 'danger');
}
-}
+}
\ No newline at end of file