2.1 now support Datasets with repeating subfields and repeating text fields. Repeating subfieds support custom snippets and validation just like regular fields.
This work is inspired by the excellent ckanext-composite
extension and replaces ckanext-repeating
You must be using CKAN 2.8 or later and a custom IPackageController plugin to index datasets with repeating subfields.
Repeating subfields let you define a group of fields to repeat within dataset and resource forms. All of the features available for normal ckanext-scheming fields can be used in subfields.
may be used to provide a singular label for each group of subfields.
contains a list of field definitions to repeat.
- field_name: submission
- field_name: date
- field_name: text
- field_name: flags
- label: Draft
- label: Approved
- label: Response Required
Data stored in subfields is represented as lists of JSON objects in the API.
"text": "an example submission",
"text": "another one",
Normal and custom validation rules apply and are displayed in the form by referencing the subfield group and the field with the error, e.g. “Submission 2: Text: Missing value”
Indexing Repeating Subfields
Repeating subfields can’t be indexed in Solr with CKAN’s default schema and indexing code since they expect extra fields to contain simple string values. Create a new IPackageController
and Solr schema to handle indexing repeating subfields the best way for your own site.
Map submission dataset fields to Solr fields
def before_index(self, data_dict):
flags = set()
text = 
for sub in data_dict.get('submission', ):
flags |= set(sub['flags'])
data_dict['submission'] = '\n'.join(text)
data_dict['submission_flags'] = sorted(flags)
to accept multiple values we must add a multivalued field to our Solr schema
<field name="submission_flags" type="string" indexed="true" stored="true" multiValued="true"/>
These new fields will now be available for use with CKAN advanced search
If you don’t need advanced search or faceting based on repeating subfields you may use the included
plugin. This plugin passes repeating fields to Solr as JSON strings to prevent indexing errors instead and doesn’t require a customized Solr schema.
Future CKAN support for dynamic fields in Solr will simplify this required configuration.
Some features not yet supported:
- validating the number of subfield groups (e.g. requiring at least one)
- nesting repeating subfields
If you need these features consider discussing your work on a new issue
and working a pull request.
Multiple text fields improve on the
fields from ckanext-repeating with a dynamic form with add and remove buttons.
- field_name: contributors
Data stored in repeating text fields is represented as lists of strings in the API.
may be used to require at least one entry. Per-field and other types of validation are not yet implemented. Add a comment to the multiple text validation issue
if you would like to work on this feature.