Commit 4d6c1caa authored by Arnaud Fontaine's avatar Arnaud Fontaine

erp5_autocompletion_list: Move away generic JS code from RelationField as it...

erp5_autocompletion_list: Move away generic JS code from RelationField as it should be reusable anywhere.
parent ce528520
...@@ -84,9 +84,32 @@ $(function() {\n ...@@ -84,9 +84,32 @@ $(function() {\n
* });\n * });\n
*/\n */\n
$.fn.ERP5Autocomplete = function(kw) {\n $.fn.ERP5Autocomplete = function(kw) {\n
return this.autocomplete({source: generateSource(kw),\n var autocomplete = \n
delay: 600,\n this.autocomplete({source: generateSource(kw),\n
search: search});\n delay: 600,\n
search: search})\n
.keyup(function(event) {\n
// With Input Method Editor, Enter allows to select between choices\n
if(event.keyCode == 13)\n
$(this).autocomplete("search");\n
});\n
\n
autocomplete = autocomplete.data("autocomplete") ?\n
// jQuery UI <= 1.8\n
autocomplete.data("autocomplete") :\n
// jQuery UI > 1.8\n
autocomplete.data("ui-autocomplete");\n
\n
autocomplete._renderItem = function(ul, item) {\n
return $("<li></li>").data("item.autocomplete", item)\n
.append("<a><b>" +\n
item.label +\n
\'</b><br><span style="font-size: 70%">\' +\n
item.description + "</span></a>")\n
.appendTo(ul);\n
};\n
\n
return autocomplete;\n
};\n };\n
});\n });\n
</tal:block> </tal:block>
......
2014-02-07 arnaud.fontaine
* Move away generic JS code from RelationField as it should be reusable anywhere.
2014-02-06 arnaud.fontaine 2014-02-06 arnaud.fontaine
* Limit the number of results to 15 instead of 20 as it seems to be enough (taken from an existing customer project). * Limit the number of results to 15 instead of 20 as it seems to be enough (taken from an existing customer project).
......
14 15
\ No newline at end of file \ No newline at end of file
...@@ -381,29 +381,8 @@ class MultiRelationStringFieldWidget(Widget.LinesTextAreaWidget, ...@@ -381,29 +381,8 @@ class MultiRelationStringFieldWidget(Widget.LinesTextAreaWidget,
return """ return """
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() { $(document).ready(function() {
var autocomplete = $("input[name='%s']").ERP5Autocomplete({search_portal_type: %s, $("input[name='%s']").ERP5Autocomplete({search_portal_type: %s,
search_catalog_key: "%s"}) search_catalog_key: "%s"});
.keyup(function(event) {
// With Input Method Editor, Enter allows to select between choices
if(event.keyCode == 13) {
$(this).autocomplete("search");
}
});
autocomplete = autocomplete.data("autocomplete") ?
// jQuery UI <= 1.8
autocomplete.data("autocomplete") :
// jQuery UI > 1.8
autocomplete.data("ui-autocomplete");
autocomplete._renderItem = function(ul, item) {
return $("<li></li>").data("item.autocomplete", item)
.append("<a><b>" +
item.label +
"</b><br><span style='font-size:70%%;'>" +
item.description + "</span></a>" )
.appendTo(ul);
};
}); });
</script>""" % (key, </script>""" % (key,
json.dumps(map(lambda x: x[0], field.get_value('portal_type'))), json.dumps(map(lambda x: x[0], field.get_value('portal_type'))),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment