Skip to content

Change the type of input fields โ€‹

The search form contains many input fields for Filters/Metadata and Annotations, and you can customize what widget is shown for each field.

Overview โ€‹

Widget types can be set for:

  • Metadata fields (filters)
  • Annotation fields (token-level attributes)

Most widgest can easily be configured in the .blf.yaml file, but some widgets require a bit more work, as they need some extra data not available in the .blf.yaml file.

Annotations โ€‹

Widgets for Annotations can be configured in two ways:

  • By setting the uiType of an annotation in the .blf.yaml
  • Through the JS customization API.
yaml
# NOTE: uiType in the `.blf.yaml` cannot be changed after creating the corpus.
# Changing it later requires manual editing of the index metadata (not recommended), 
# or recreating of the index/corpus.
metadata: 
  fields: 
  - name: author
    uiType: select
  - name: year
    uiType: range
ts
function customizeUIType(
  annotatedField: NormalizedAnnotatedField, 
  annotation: NormalizedAnnotation
) {
  // For example:
  switch (annotation.id) {
    case 'author': return 'select';
    case 'year': return 'range';
    default: return null; // use default
  }
}

frontend.customize(corpus => {
  // The function you set will be called for every shown annotation:
  corpus.search.pattern.uiType = customizeUIType;
})

Annotation Widgets โ€‹

The following widgets are available for Annotations, use the name of the tab as the uiType in the .blf.yaml file, or return it from the customizeUIType function.

Metadata (Filters) โ€‹

Widgets for Metadata can be configured in two ways:

  • By setting the uiType of a metadata field in the .blf.yaml
  • By manually creating the filter with a different type with the JS API.
yaml
metadata: 
  fields: 
  - name: genre
    uiType: checkbox
  - name: date
    uiType: date
ts
vuexModules.filters.actions.registerFilter({filter: {
  id: 'genre', // must match the metadata field name, except where otherwise stated
  componentName: 'filter-checkbox', // 'filter-' followed by the widget type

  displayName: 'Genre',
  description: 'Genre of the text',

  metadata: {} // extra info required for the widget. Differs per filter type, see below.
}});

Apache license 2.0