handleSelectElement function
Last updated: 2026-03-04T23:21:38.398Z
Location
Metrics
LOC: 30
Complexity: 4
Params: 2
Signature
handleSelectElement(element: HTMLSelectElement, value: string): : void
Source Code
function handleSelectElement(element: HTMLSelectElement, value: string): void {
const options = Array.from(element.options);
// Try to match by value first
const byValue = options.find((opt) => opt.value === value);
if (byValue) {
element.value = byValue.value;
element.dispatchEvent(new Event("change", { bubbles: true }));
return;
}
// Try to match by text
const byText = options.find((opt) =>
opt.text.toLowerCase().includes(value.toLowerCase()),
);
if (byText) {
element.value = byText.value;
element.dispatchEvent(new Event("change", { bubbles: true }));
return;
}
// Pick a random non-empty option
const validOptions = options.filter((opt) => opt.value);
if (validOptions.length > 0) {
const random =
validOptions[Math.floor(Math.random() * validOptions.length)];
element.value = random.value;
element.dispatchEvent(new Event("change", { bubbles: true }));
}
}
No outgoing dependencies.
Impact (Incoming)
| Source | Type |
|---|---|
| applyValueToField | calls |