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

Document how to set default value

Open florianm opened this issue 3 years ago • 0 comments

Problem

I would like to set a default for some fields.

Research

Read README, examples, issues, browsed code, no definite pointer.

Searching the ckanext-scheming repo for "default" brought up https://github.com/ckan/ckanext-scheming/blob/d441d2dee72a7382a73de4185b01fae4b2d37473/ckanext/scheming/templates/scheming/package/snippets/resource_form.html#L31-L33

Suggestions

The docs and examples could have a friendly pointer on how to set defaults, such as:

There are three ways to choose a default value.

First, if required is set on a choices list, the first option will be selected. (HT @jqnatividad https://github.com/ckan/ckanext-scheming/issues/265)

Second, the key default sets an explicit default, and works on any field. The value must be valid as per the field's datatype and validators, or exist in the choices.

- field_name: license_id
  label: License
  display_property: dcat:Dataset/dcat:distribution/dcat:Distribution/dct:license
  form_snippet: license.html
  default: "cc-by-sa"

Third, field values can be supplied through GET request parameters to "Add dataset". (HT @wardi https://github.com/ckan/ckanext-scheming/issues/258)

/dataset/new?notes=some_default_notes

florianm avatar Aug 04 '22 02:08 florianm