CxJS

LookupField

import { LookupField } from 'cx/widgets'; Copied

The LookupField widget offers selection from a list of available options. It’s similar to the native HTML select element but provides additional features:

  • Searching/filtering the list
  • Querying remote data
  • User-friendly multiple selection with tags
<LabelsTopLayout columns={2}>
  <LookupField
    label="Single Select"
    value={bind(m.selectedId, 1)}
    text={bind(m.selectedText, "Apple")}
    options={options}
  />
  <LookupField
    label="Multiple Select"
    records={m.selectedRecords}
    options={options}
    multiple
  />
</LabelsTopLayout>
Apple
 

Remote Data

Use onQuery to fetch options from a server. The callback receives the search query and should return a list of options or a Promise.

Use fetchAll to fetch all data once and filter client-side, which is more efficient for moderate-sized datasets. Add cacheAll to keep the fetched data cached for the widget’s lifetime, avoiding refetches when the dropdown reopens.

<LabelsTopLayout columns={2}>
  <LookupField
    label="Query on Each Keystroke"
    value={m.cityId}
    text={m.cityText}
    onQuery={queryCity}
    minQueryLength={2}
    placeholder="Type at least 2 chars..."
  />
  <LookupField
    label="Fetch Once, Filter Locally"
    records={m.cities}
    onQuery={queryCity}
    fetchAll
    cacheAll
    multiple
    placeholder="Type to filter..."
  />
</LabelsTopLayout>
Type at least 2 chars...
Type to filter...

Data Binding

Selection ModeLocal (options)Remote (onQuery)
Singlevalue and/or textvalue and text
Multiplevalues and/or recordsrecords

Examples

Configuration

Core Properties

PropertyTypeDefaultDescription
valueanySelected value ID (single mode)
textstringSelected value text (single mode)
valuesarrayArray of selected IDs (multiple mode)
recordsarrayArray of selected records (multiple mode)
optionsarrayArray of available options
multiplebooleanfalseEnable multiple selection
placeholderstringPlaceholder text when empty
disabledbooleanfalseDisables the field
readOnlybooleanfalseMakes the field read-only

Option Fields

PropertyTypeDefaultDescription
optionIdFieldstring"id"Field name for option ID
optionTextFieldstring"text"Field name for option display text
valueIdFieldstring"id"Field name for storing ID in selection
valueTextFieldstring"text"Field name for storing text in selection

Query Options

PropertyTypeDefaultDescription
onQueryfunction(query, instance) => options[] - Fetch options
queryDelaynumber150Delay in ms before query is executed
minQueryLengthnumber0Minimum characters before query is made
fetchAllbooleanfalseFetch all options once, filter client-side
cacheAllbooleanfalseCache fetched options for widget lifetime
infinitebooleanfalseEnable infinite scrolling for large datasets
pageSizenumber100Number of items per page in infinite mode

Appearance

PropertyTypeDefaultDescription
iconstringIcon displayed on the left side
showClearbooleantrueShows clear button when value is present
hideClearbooleanfalseHides the clear button
alwaysShowClearbooleanfalseShows clear button even when required
hideSearchFieldbooleanfalseHide the search input in dropdown
minOptionsForSearchFieldnumber7Minimum options before search field is shown

Behavior

PropertyTypeDefaultDescription
closeOnSelectbooleantrueClose dropdown after selection
autoOpenbooleanfalseOpen dropdown on focus
quickSelectAllbooleanfalseAllow Ctrl+A to select all visible options
sortbooleanfalseSort dropdown options alphabetically

Messages

PropertyTypeDefaultDescription
loadingTextstring"Loading..."Text shown while loading
noResultsTextstring"No results found."Text when no options match
queryErrorTextstring"Error occurred while querying..."Text on query error
minQueryLengthMessageTextstring"Type in at least {0} character(s)."Text when query is too short