ckanext-scheming icon indicating copy to clipboard operation
ckanext-scheming copied to clipboard

Tags-like field with open vocabulary

Open davidlesieur opened this issue 2 years ago • 1 comments

I am trying to create a custom field that would behave like the Tags field, i.e., with autocomplete for existing tags, and the ability to add new tags if desired, except that the field would work with a specific vocabulary rather than the default tags vocabulary.

To that end, I have:

  • Created the vocabulary with the vocabulary_create action.
  • Defined the field as follows in my dataset schema:
    - field_name: dimension
      label: Dimensions
      form_placeholder: eg. Age Groups, Mother Tongue, First Official Language Spoken
      validators: ignore_missing tag_string_convert
      classes:
        - control-full
      form_attrs:
        data-module: autocomplete
        data-module-tags:
        data-module-source: /api/2/util/tag/autocomplete?vocabulary_id=dimension&incomplete=?
        class:
    
    (This takes advantage of the autocomplete API accepting the vocabulary_id parameter).

With that field definition, autocomplete searches the desired vocabulary, and new tags can be entered.

However, the part I'm not figuring out is how to get new tags to be saved in the proper vocabulary. At this point, new tags are always saved in the default tags vocabulary (with an empty vocabulary id). Ideas?

davidlesieur avatar Jan 29 '23 02:01 davidlesieur

Does ckanext-scheming actually supports what I'm trying to achieve? Thanks.

davidlesieur avatar Feb 01 '23 23:02 davidlesieur