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.

TIP

JavaScript snippets on this page should go in a custom JS file. See here and the tutorial here.

Overview โ€‹

Widget types can be set for:

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

Most widgets 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) โ€‹

Set a metadata field's uiType in the .blf.yaml file, or replace the filter in the search form graph.

yaml
metadata:
  fields:
  - name: genre
    uiType: checkbox
  - name: date
    uiType: date
js
frontend.customizeSearchForm({
  customize(form) {
    const field = form.corpus.allMetadataFieldsMap.genre;
    const id = form.ids.metadataFilter('genre');
    if (field?.values?.length && form.graph.getField(id)) {
      form.graph.replaceNode(id, form.metadataCheckbox(field, { id, options: field.values }));
    }
  },
});

Apache license 2.0