[1730][forms, templates] use a html select for
vocab tags instead of standard (free) input field
--- a/ckanext/example/forms.py
+++ b/ckanext/example/forms.py
@@ -204,7 +204,7 @@
schema = package_form_schema()
schema.update({
'published_by': [not_empty, unicode, convert_to_extras],
- 'vocab_tag_string': [ignore_missing, convert_to_tags(self.vocab_name)],
+ 'vocab_tags': [ignore_missing, convert_to_tags(self.vocab_name)],
})
return schema
@@ -218,7 +218,7 @@
'tags': {
'__extras': [keep_extras, free_tags_only]
},
- 'vocab_tag_string': [convert_from_tags(self.vocab_name), ignore_missing],
+ 'vocab_tags_selected': [convert_from_tags(self.vocab_name), ignore_missing],
'published_by': [convert_from_extras, ignore_missing],
})
return schema
--- a/ckanext/example/theme/templates/forms/dataset_form.html
+++ b/ckanext/example/theme/templates/forms/dataset_form.html
@@ -147,8 +147,14 @@
<dl>
<dt class="tags-label"><label class="field_opt" for="tags_vocab">Tags</label></dt>
<dd class="tags-field">
- <input class="long autocomplete-tag" id="vocab_tag_string" name="vocab_tag_string" size="60" type="text"
- value="${data.get('vocab_tag_string') or ', '.join([tag['name'] for tag in data.get('vocab_tags', [])])}" />
+ <select id="vocab_tags" name="vocab_tags" size="60" multiple="multiple">
+ <py:for each="tag in c.vocab_tags">
+ <py:choose test="">
+ <option py:when="tag in data.get('vocab_tags_selected', [])" selected="selected" value="${tag}">${tag}</option>
+ <option py:otherwise="" value="${tag}">${tag}</option>
+ </py:choose>
+ </py:for>
+ </select>
</dd>
<dd class="tags-instructions instructions basic" i18n:msg="">Similar to standard CKAN tags, but these use a fixed vocabulary.</dd>
<dd class="tags-instructions field_error" py:if="errors.get('vocab_tag_string', '')">${errors.get('vocab_tag_string', '')}</dd>