Updated Select2 widgets templates in display mode
authorThierry Florac <tflorac@ulthar.net>
Fri, 26 Jul 2019 12:33:02 +0200
changeset 179 f9147cd3fe5b
parent 178 afd8c5647c93
child 180 2f4027a2d6c8
Updated Select2 widgets templates in display mode
src/pyams_form/widget/__init__.py
src/pyams_form/widget/templates/hidden-select-display.pt
src/pyams_form/widget/templates/select-display.pt
--- a/src/pyams_form/widget/__init__.py	Thu Jul 25 12:06:22 2019 +0200
+++ b/src/pyams_form/widget/__init__.py	Fri Jul 26 12:33:02 2019 +0200
@@ -10,8 +10,6 @@
 # FOR A PARTICULAR PURPOSE.
 #
 
-__docformat__ = 'restructuredtext'
-
 import inspect
 import json
 import locale
@@ -48,6 +46,9 @@
 from pyams_utils.schema import IColorField, IHTMLField, ITextLineListField
 from pyams_utils.timezone import localgmtime, tztime
 
+
+__docformat__ = 'restructuredtext'
+
 from pyams_form import _
 
 
@@ -551,6 +552,7 @@
 #
 
 @widgettemplate_config(mode=INPUT_MODE, template='templates/select-input.pt', layer=IFormLayer)
+@widgettemplate_config(mode=DISPLAY_MODE, template='templates/select-display.pt', layer=IFormLayer)
 @implementer_only(ISelect2Widget)
 class Select2Widget(SelectWidget):
     """Select2 widget"""
@@ -568,6 +570,7 @@
 
 
 @widgettemplate_config(mode=INPUT_MODE, template='templates/hidden-select-input.pt', layer=IFormLayer)
+@widgettemplate_config(mode=DISPLAY_MODE, template='templates/hidden-select-display.pt', layer=IFormLayer)
 @implementer(IObjectData)
 class HiddenSelect2Widget(Select2Widget):
     """Hidden select2 widget
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_form/widget/templates/hidden-select-display.pt	Fri Jul 26 12:33:02 2019 +0200
@@ -0,0 +1,31 @@
+<label class="input bordered"
+	   tal:omit-tag="view/required" i18n:domain="onf_website">
+	<div class="select2-parent"
+		 tal:omit-tag="view/required">
+		<input type="hidden" autocomplete="none"
+				class="select2" disabled="disabled"
+				data-ams-select2-separator="|"
+				tal:attributes="id view/id;
+								name string:${view/name};
+								class string:${view/klass} select2;
+								style view/style;
+								title view/title;
+								value view/values;
+								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;
+								tabindex view/tabindex;
+								onchange view/onchange;
+								data-ams-data tales:object_data(view);
+								data-ams-select2-values view/values_map;
+								data-ams-select2-multiple python:'true' if view.multiple else None;" />
+	</div>
+</label>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_form/widget/templates/select-display.pt	Fri Jul 26 12:33:02 2019 +0200
@@ -0,0 +1,35 @@
+<label class="input bordered"
+	   tal:omit-tag="view/required" i18n:domain="pyams_form">
+	<div class="select2-parent"
+		 tal:omit-tag="view/required">
+		<select class="select2" disabled="disabled"
+				tal:attributes='id view/id;
+								name string:${view/name}:list;
+								class string:${view/klass} select2;
+								style view/style;
+								title view/title;
+								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;
+								tabindex view/tabindex;
+								onfocus view/onfocus;
+								onblur view/onblur;
+								onchange view/onchange;
+								multiple view/multiple;
+								size view/size;
+								data-ams-data tales:object_data(view);'>
+			<option tal:repeat="entry view/items"
+					tal:attributes="value entry/value;
+									selected python:entry['value'] in view.value;"
+					tal:content="python:view.get_content(entry) if hasattr(view, 'get_content') else entry['content']"></option>
+		</select>
+	</div>
+</label>
\ No newline at end of file