correctly setting the current model in the special prompts pages

This commit is contained in:
Mic 2026-03-25 00:13:00 +01:00
parent 7cde1f9b62
commit a1bd5d71e6
5 changed files with 68 additions and 54 deletions

View file

@ -330,19 +330,21 @@ async function restoreOptions() {
const restoreValue = result[element.id] || default_select_value; const restoreValue = result[element.id] || default_select_value;
// Check if option exists // Check if option exists
let optionExists = Array.from(element.options).some(opt => opt.value === restoreValue); let optionExists = Array.from(element.options).some(opt => opt.value === restoreValue);
// If it doesn't exist and restoreValue is not empty, create it
if (!optionExists && restoreValue !== '') {
let newOption = new Option(restoreValue, restoreValue);
element.add(newOption);
}
// Set value
element.value = restoreValue;
if (element.value === '') {
element.selectedIndex = -1;
}
if (element.tomselect) { if (element.tomselect) {
element.tomselect.setValue(element.value, true); if (!optionExists && restoreValue !== '') {
element.tomselect.addOption({ value: restoreValue, text: restoreValue });
}
element.tomselect.setValue(restoreValue, true);
setTomSelectBorder(element.tomselect); setTomSelectBorder(element.tomselect);
} else {
if (!optionExists && restoreValue !== '') {
let newOption = new Option(restoreValue, restoreValue);
element.add(newOption);
}
element.value = restoreValue;
if (element.value === '') {
element.selectedIndex = -1;
}
} }
}else{ }else{
console.error("[ThunderAI] Unhandled input type:", element.type); console.error("[ThunderAI] Unhandled input type:", element.type);

View file

@ -227,19 +227,21 @@ async function restoreOptions() {
const restoreValue = result[element.id] || default_select_value; const restoreValue = result[element.id] || default_select_value;
// Check if option exists // Check if option exists
let optionExists = Array.from(element.options).some(opt => opt.value === restoreValue); let optionExists = Array.from(element.options).some(opt => opt.value === restoreValue);
// If it doesn't exist and restoreValue is not empty, create it
if (!optionExists && restoreValue !== '') {
let newOption = new Option(restoreValue, restoreValue);
element.add(newOption);
}
// Set value
element.value = restoreValue;
if (element.value === '') {
element.selectedIndex = -1;
}
if (element.tomselect) { if (element.tomselect) {
element.tomselect.setValue(element.value, true); if (!optionExists && restoreValue !== '') {
element.tomselect.addOption({ value: restoreValue, text: restoreValue });
}
element.tomselect.setValue(restoreValue, true);
setTomSelectBorder(element.tomselect); setTomSelectBorder(element.tomselect);
} else {
if (!optionExists && restoreValue !== '') {
let newOption = new Option(restoreValue, restoreValue);
element.add(newOption);
}
element.value = restoreValue;
if (element.value === '') {
element.selectedIndex = -1;
}
} }
}else{ }else{
console.error("[ThunderAI] Unhandled input type:", element.type); console.error("[ThunderAI] Unhandled input type:", element.type);

View file

@ -180,19 +180,21 @@ async function restoreOptions() {
const restoreValue = result[element.id] || default_select_value; const restoreValue = result[element.id] || default_select_value;
// Check if option exists // Check if option exists
let optionExists = Array.from(element.options).some(opt => opt.value === restoreValue); let optionExists = Array.from(element.options).some(opt => opt.value === restoreValue);
// If it doesn't exist and restoreValue is not empty, create it
if (!optionExists && restoreValue !== '') {
let newOption = new Option(restoreValue, restoreValue);
element.add(newOption);
}
// Set value
element.value = restoreValue;
if (element.value === '') {
element.selectedIndex = -1;
}
if (element.tomselect) { if (element.tomselect) {
element.tomselect.setValue(element.value, true); if (!optionExists && restoreValue !== '') {
element.tomselect.addOption({ value: restoreValue, text: restoreValue });
}
element.tomselect.setValue(restoreValue, true);
setTomSelectBorder(element.tomselect); setTomSelectBorder(element.tomselect);
} else {
if (!optionExists && restoreValue !== '') {
let newOption = new Option(restoreValue, restoreValue);
element.add(newOption);
}
element.value = restoreValue;
if (element.value === '') {
element.selectedIndex = -1;
}
} }
}else{ }else{
console.error("[ThunderAI] Unhandled input type:", element.type); console.error("[ThunderAI] Unhandled input type:", element.type);

View file

@ -326,17 +326,21 @@ async function restoreOptions() {
const restoreValue = result[element.id] || default_select_value; const restoreValue = result[element.id] || default_select_value;
// Ensure option exists before restoring // Ensure option exists before restoring
let optionExists = Array.from(element.options).some(opt => opt.value === restoreValue); let optionExists = Array.from(element.options).some(opt => opt.value === restoreValue);
if (!optionExists && restoreValue !== '') {
let newOption = new Option(restoreValue, restoreValue);
element.add(newOption);
}
element.value = restoreValue;
if (element.value === '') {
element.selectedIndex = -1;
}
if (element.tomselect) { if (element.tomselect) {
element.tomselect.setValue(element.value, true); if (!optionExists && restoreValue !== '') {
element.tomselect.addOption({ value: restoreValue, text: restoreValue });
}
element.tomselect.setValue(restoreValue, true);
setTomSelectBorder(element.tomselect); setTomSelectBorder(element.tomselect);
} else {
if (!optionExists && restoreValue !== '') {
let newOption = new Option(restoreValue, restoreValue);
element.add(newOption);
}
element.value = restoreValue;
if (element.value === '') {
element.selectedIndex = -1;
}
} }
}else{ }else{
console.error("[ThunderAI] Unhandled input type:", element.type); console.error("[ThunderAI] Unhandled input type:", element.type);

View file

@ -32,7 +32,8 @@ import {
import { textareaAutocomplete } from "../../js/mzta-placeholders-autocomplete.js"; import { textareaAutocomplete } from "../../js/mzta-placeholders-autocomplete.js";
import { import {
normalizeStringList, normalizeStringList,
isAPIKeyValue isAPIKeyValue,
setTomSelectBorder
} from "../../js/mzta-utils.js"; } from "../../js/mzta-utils.js";
import { import {
initializeSpecificIntegrationUI initializeSpecificIntegrationUI
@ -246,18 +247,21 @@ async function restoreOptions() {
const restoreValue = result[element.id] ?? default_select_value; const restoreValue = result[element.id] ?? default_select_value;
// Check if option exists // Check if option exists
let optionExists = Array.from(element.options).some(opt => opt.value === String(restoreValue)); let optionExists = Array.from(element.options).some(opt => opt.value === String(restoreValue));
// If it doesn't exist and restoreValue is not empty, create it
if (!optionExists && restoreValue !== '') {
let newOption = new Option(restoreValue, restoreValue);
element.add(newOption);
}
// Set value
element.value = restoreValue;
if (element.value === '') {
element.selectedIndex = 0;
}
if (element.tomselect) { if (element.tomselect) {
element.tomselect.setValue(element.value, true); if (!optionExists && restoreValue !== '') {
element.tomselect.addOption({ value: String(restoreValue), text: String(restoreValue) });
}
element.tomselect.setValue(String(restoreValue), true);
setTomSelectBorder(element.tomselect);
} else {
if (!optionExists && restoreValue !== '') {
let newOption = new Option(restoreValue, restoreValue);
element.add(newOption);
}
element.value = restoreValue;
if (element.value === '') {
element.selectedIndex = 0;
}
} }
}else{ }else{
console.error("[ThunderAI] Unhandled input type:", element.type); console.error("[ThunderAI] Unhandled input type:", element.type);