--- a/src/pyams_thesaurus/widget/__init__.py Wed Jul 22 17:22:01 2015 +0200
+++ b/src/pyams_thesaurus/widget/__init__.py Wed Jul 22 17:23:33 2015 +0200
@@ -135,7 +135,8 @@
thesaurus = query_utility(IThesaurus, name=thesaurus_name)
if thesaurus is None:
return None
- value = value.split('|')
+ if isinstance(value, str):
+ value = value.split('|')
for idx, val in enumerate(value):
match = SYNONYM.match(val)
if match:
@@ -169,3 +170,17 @@
def ThesaurusTermsListFieldWidget(field, request):
"""Thesaurus terms list field widget factory"""
return FieldWidget(field, ThesaurusTermsListWidget(request))
+
+
+#
+# Terms list widget with selector
+#
+
+@widgettemplate_config(mode='input', template='templates/terms-list-selector-input.pt', layer=IFormLayer)
+class ThesaurusTermsListSelectorWidget(ThesaurusTermsListWidget):
+ """Thesaurus terms list widget with selector"""
+
+
+def ThesaurusTermsListSelectorFieldWidget(field, request):
+ """Thesaurus terms list field widget with selector factory"""
+ return FieldWidget(field, ThesaurusTermsListSelectorWidget(request))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_thesaurus/widget/templates/terms-list-selector-input.pt Wed Jul 22 17:23:33 2015 +0200
@@ -0,0 +1,48 @@
+<label class="input bordered with-icons" i18n:domain="pyams_thesaurus">
+ <i class="icon-append fa fa-trash-o hint opaque"
+ title="Clear selected values" i18n:attributes="title"
+ tal:omit-tag="view/required"
+ data-ams-click-handler="MyAMS.helpers.select2ClearSelection"
+ tal:attributes="data-ams-select2-target view/name"></i>
+ <i class="icon-append icon-append-2 fa fa-th-list hint opaque"
+ title="Show terms selector" i18n:attributes="title"
+ data-ams-url="MyAMS.helpers.select2ClearSelection"
+ data-toggle="modal"
+ tal:attributes="data-ams-select2-target view/name"></i>
+ <div class="select2-parent">
+ <input type="hidden" autocomplete="off"
+ data-ams-select2-minimum-input-length="2"
+ data-ams-select2-allow-clear="true"
+ data-ams-select2-multiple="true"
+ data-ams-select2-separator="|"
+ data-ams-select2-query-method="findTerms"
+ data-ams-select2-method-target="/api/thesaurus/json"
+ tal:attributes="id view/id;
+ name view/name;
+ class string:select2 ${view/klass};
+ style view/style;
+ title view/title;
+ value python:'|'.join(view.value or ());
+ lang view/lang;
+ onclick view/onclick;
+ ondblclick view/ondblclick;
+ onmousedown view/onmousedown;
+ onmouseup view/onmouseup;
+ onmouseover view/onmouseover;
+ onmousemove view/onmousemove;
+ onmouseout view/onmouseout;
+ onkeypress view/onkeypress;
+ onkeydown view/onkeydown;
+ onkeyup view/onkeyup;
+ disabled view/disabled;
+ tabindex view/tabindex;
+ onfocus view/onfocus;
+ onblur view/onblur;
+ onchange view/onchange;
+ readonly view/readonly;
+ accesskey view/accesskey;
+ onselect view/onselect;
+ data-ams-select2-values view/values_map;
+ data-ams-select2-query-params view/query_params;" />
+ </div>
+</label>