Skip to content

User Selector

A single user dropdown fed by ApiClient.getUsers(). It is also on the bag as shared.createUserSelector.

Decision

When Use
Picking one Jellyfin user, such as an approver User Selector
Several users User Multi Selector

Usage

var approver = shared.createUserSelector({
    adminFilter: 'exclude',
    value: config.ApproverId,
    onChange: function (id) { tracker.check(); }
});
container.appendChild(approver.element);

The handle is { element, ready, getValue, setValue, refresh, setSize, destroy }. The markup is div.stolon-selector.stolon-user-selector around select.stolon-selector-dropdown.stolon-user-select.

States and Modifiers

  • adminFilter is 'all' (default), 'exclude' to hide administrators, or 'only'.
  • value is a user id. Matching ignores case and dashes.
  • A none entry comes first, and includeEmptyOption: false leaves it out. emptyLabel is its text, "None" by default.
  • Administrator names end in " (admin)", and showAdminBadge: false leaves it off.
  • fetchUsers() replaces the ApiClient.getUsers() source and may return an array or { Items }.
  • Users are sorted by name. A failed fetch gives an empty list rather than an error.
  • It is a native select, so keyboard and ARIA are the browser's.
  • size is small, medium (default), or large, and sizes its fields on the size scale. setSize(size) changes it later.

Gotchas

  • stolon-user-selector and stolon-user-select are hooks with no CSS rules.
  • destroy() does nothing, since there are no document listeners.
  • ready resolves after the list renders.

Reference

Generated from the code by scripts/build-docs.mjs. Edit the code, not this section.

createUserSelector

function createUserSelector(options?: UserSelectorOptions): UserSelectorHandle

Builds a single-user dropdown from the server's user list.

Option Type What it does
value string preselected user id [optional]
includeEmptyOption boolean add a none entry (default true)
emptyLabel string label for the none entry (default 'None')
showAdminBadge boolean append " (admin)" to administrator names (default true)
size 'small' | 'medium' | 'large' 'small', 'medium', or 'large' for its fields (default 'medium')
onChange (userId: string): void function(userId) called on selection change [optional]
Handle member Type
ready Promise<SelectorUser[]>
getValue (): string
setValue (id: string | null): void
refresh (): Promise<SelectorUser[]>
setSize (size?: 'small' | 'medium' | 'large'): void
destroy (): void
Type What it is
SelectorUser A user after normalizeUser reads it, as the selectors draw it.
RawUser A user record from ApiClient.getUsers() or a plugin DTO, in either PascalCase or camelCase.
AdminFilter Keeps everyone, hides administrators, or keeps only administrators.
UserSource The options both selectors read to load the user list.

Example

Example Code

<!-- title: User Selector -->
<div id="mount"></div>
<span id="userStatus" class="stolon-status-text"></span>
<script type="module">
const base = await window.__baseReady;
const shared = base.createShared(document.getElementById('view'), 'preview-plugin', 'Preview');
const approver = shared.createUserSelector({
    adminFilter: 'exclude',
    value: 'u2',
    onChange: (id) => shared.setStatus('userStatus', 'Chose user ' + (id || 'none') + '.', false, { timeout: 0 })
});
document.getElementById('mount').appendChild(approver.element);
</script>