##// END OF EJS Templates
deform: fixed selecting of default values for select2 widget.
marcink -
r1713:9aa5eba6 default
parent child Browse files
Show More
@@ -1,55 +1,55 b''
1 1 <div tal:define="
2 2 name name|field.name;
3 3 style field.widget.style;
4 4 oid oid|field.oid;
5 5 css_class css_class|field.widget.css_class;
6 6 optgroup_class optgroup_class|field.widget.optgroup_class;
7 7 multiple multiple|field.widget.multiple;"
8 8 tal:omit-tag="">
9 9 <input type="hidden" name="__start__" value="${name}:sequence"
10 10 tal:condition="multiple" />
11 11
12 12 <select tal:attributes="
13 13 name name;
14 14 id oid;
15 15 class string: form-control ${css_class or ''};
16 16 data-placeholder field.widget.placeholder|None;
17 17 multiple multiple;
18 18 style style;">
19 19 <tal:loop tal:repeat="item values">
20 20 <optgroup tal:condition="isinstance(item, optgroup_class)"
21 21 tal:attributes="label item.label">
22 22 <option tal:repeat="(value, description) item.options"
23 23 tal:attributes="
24 selected (multiple and value in list(map(unicode, cstruct)) or value == list(map(unicode, cstruct))) and 'selected';
24 selected python:field.widget.get_select_value(cstruct, value);
25 25 class css_class;
26 26 label field.widget.long_label_generator and description;
27 27 value value"
28 28 tal:content="field.widget.long_label_generator and field.widget.long_label_generator(item.label, description) or description"/>
29 29 </optgroup>
30 30 <option tal:condition="not isinstance(item, optgroup_class)"
31 31 tal:attributes="
32 selected (multiple and item[0] in list(map(unicode, cstruct)) or item[0] == unicode(cstruct)) and 'selected';
32 selected python:field.widget.get_select_value(cstruct, item[0]);
33 33 class css_class;
34 34 value item[0]">${item[1]}</option>
35 35 </tal:loop>
36 36 </select>
37 37
38 38 <script type="text/javascript">
39 39 deform.addCallback(
40 '${field.oid}',
40 '${oid}',
41 41 function(oid) {
42 42 $('#' + oid).select2({
43 43 containerCssClass: 'form-control drop-menu',
44 44 dropdownCssClass: 'drop-menu-dropdown',
45 45 dropdownAutoWidth: true,
46 46 placeholder: "${str(field.widget.placeholder).replace('"','\\"')|""}",
47 47 allowClear: true
48 48 });
49 49 }
50 50 );
51 51 </script>
52 52
53 53 <input type="hidden" name="__end__" value="${name}:sequence"
54 54 tal:condition="multiple" />
55 55 </div> No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now