makeSelect2Container function infrastructure

Last updated: 2026-03-01T23:25:47.095Z

Metrics

LOC: 45 Complexity: 2 Params: 2

Signature

makeSelect2Container( opts: Array<{ value: string; text: string }> = [], ): : { container: HTMLElement; select: HTMLSelectElement; }

Source Code

function makeSelect2Container(
  opts: Array<{ value: string; text: string }> = [],
): {
  container: HTMLElement;
  select: HTMLSelectElement;
} {
  const wrapper = document.createElement("div");
  wrapper.className = "some-field-wrapper";

  const select = document.createElement("select");
  select.className = "select2-hidden-accessible";
  select.name = "myField";
  select.id = "field-id";

  const empty = document.createElement("option");
  empty.value = "";
  empty.textContent = "Choose…";
  select.appendChild(empty);

  for (const o of opts) {
    const opt = document.createElement("option");
    opt.value = o.value;
    opt.textContent = o.text;
    select.appendChild(opt);
  }

  const container = document.createElement("span");
  container.className = "select2 select2-container";

  const selection = document.createElement("span");
  selection.className = "select2-selection";

  const rendered = document.createElement("span");
  rendered.className = "select2-selection__rendered";
  rendered.textContent = "Choose…";

  selection.appendChild(rendered);
  container.appendChild(selection);

  wrapper.appendChild(select);
  wrapper.appendChild(container);
  document.body.appendChild(wrapper);

  return { container, select };
}

Dependencies (Outgoing)

graph LR makeSelect2Container["makeSelect2Container"] makeSelect2ContainerWithPlaceholder["makeSelect2ContainerWithPlaceholder"] makeSelect2Container -->|calls| makeSelect2Container makeSelect2Container -->|calls| makeSelect2ContainerWithPlaceholder style makeSelect2Container fill:#dbeafe,stroke:#2563eb,stroke-width:2px click makeSelect2Container "5b5ce8de7e193abd.html" click makeSelect2ContainerWithPlaceholder "3e7caeabc8dab136.html"

Impact (Incoming)

graph LR makeSelect2Container["makeSelect2Container"] makeSelect2ContainerWithPlaceholder["makeSelect2ContainerWithPlaceholder"] makeSelect2ContainerWithPlaceholder -->|calls| makeSelect2Container makeSelect2Container -->|calls| makeSelect2Container style makeSelect2Container fill:#dbeafe,stroke:#2563eb,stroke-width:2px click makeSelect2Container "5b5ce8de7e193abd.html" click makeSelect2ContainerWithPlaceholder "3e7caeabc8dab136.html"