diff --git a/select2-latest.html b/select2-latest.html index 4d8678f7..072deaa7 100755 --- a/select2-latest.html +++ b/select2-latest.html @@ -454,6 +454,22 @@ $("#e2_2").select2({

Example Code


+            

+ You can set data- attributes to <option> (or <optgroup>) and use them inside temptlating functions: +

+
+                <select>
+                    <option value="0" data-foo="bar">option one</option>
+                    ...
+                </select>
+            
+
+                function format(state) {
+                    var originalOption = state.element;
+                    
+                    return "<img class='flag' src='images/flags/" + state.id.toLowerCase() + ".png' alt='" + originalOption.data('foo') + "' />" + state.text;
+                }
+            
@@ -897,6 +913,14 @@ $("#e17").select2({ <returns>stringHtml that represents the selection The default implementation expects the object to have a text property that is returned. +

+ Original <option> (or <optgroup>) element is accessible inside the specified function through the property item.element: +
+                    format(item) {
+                        var originalOption = item.element;
+                        // return item.text
+                    }
+                
formatResultfunction Function used to render a result that the user can select. @@ -907,6 +931,14 @@ $("#e17").select2({ <returns>stringHtml that represents the result The default implementation expects the object to have a text property that is returned. +

+ Original <option> (or <optgroup>) element is accessible inside the specified function through the property item.element: +
+                    format(item) {
+                        var originalOption = item.element;
+                        // return item.text
+                    }
+                
formatNoMatchesfunction Function used to render the "No matches" message