Commits

Mark Lavin committed d270705

Label formatting callback function support. See #35.

Comments (0)

Files changed (1)

selectable/static/selectable/js/jquery.dj.selectable.js

         options: {
             removeIcon: "ui-icon-close",
             comboboxIcon: "ui-icon-triangle-1-s",
-            prepareQuery: null
+            prepareQuery: null,
+            highlightMatch: true,
+            formatLabel: null
         },
         
         _initDeck: function(hiddenInputs) {
                 }
             }).addClass("ui-widget ui-widget-content ui-corner-all");
             $(input).data("autocomplete")._renderItem = function(ul, item) {
-                var re = new RegExp("(?![^&;]+;)(?!<[^<>]*)(" +
-                $.ui.autocomplete.escapeRegex(this.term) +
-                ")(?![^<>]*>)(?![^&;]+;)", "gi");
-                var label = item.label.replace(re, "<span class='highlight'>$1</span>");
+                var label = item.label;
+                if (self.options.formatLabel) {
+                    label = self.options.formatLabel(label, item);
+                }
+                if (self.options.highlightMatch) {
+                    var re = new RegExp("(?![^&;]+;)(?!<[^<>]*)(" +
+                    $.ui.autocomplete.escapeRegex(this.term) +
+                    ")(?![^<>]*>)(?![^&;]+;)", "gi");
+                    label = label.replace(re, "<span class='highlight'>$1</span>");
+                }
                 var li =  $("<li></li>")
 			        .data("item.autocomplete", item)
-			        .append($("<a></a>").html(label))
+			        .append($("<a></a>").append(label))
 			        .appendTo(ul);
                 if (item.page) {
                     li.addClass('selectable-paginator');