• Build the dropdown options for a shortcode-reference field from a list of candidates. Foundry-free so it is unit-testable without a running client.

    Candidates with a blank shortcode are skipped and exclude (a self-reference shortcode) is filtered out; the remainder is sorted by label. If selected is a non-blank shortcode that matches no candidate, a flagged "<code> (unresolved)" option is appended and kept selectable so the stored value is preserved and the dangling reference is visible.

    Parameters

    • candidates: readonly RefCandidate[]

      The reference candidates ({shortcode, name}).

    • Optionalselected: null | string

      The currently-stored shortcode, if any.

    • Optionalexclude: null | string

      A shortcode to omit (e.g. the field owner, to forbid a self-reference).

    Returns ShortcodeRefOption[]

    The options, sorted by label, with any dangling selection appended.