Skip to content
This repository
Browse code

It's very useful to have the field passed into the callback

  • Loading branch information...
commit 55958361ff85baafad6fb8e9caad6aa58c060676 1 parent fc38852
Fred Wu fredwu authored
2  lib/ajax-chosen.js
@@ -62,7 +62,7 @@
62 62 select.find('optgroup:empty').each(function() {
63 63 return $(this).remove();
64 64 });
65   - items = callback != null ? callback(data) : data;
  65 + items = callback != null ? callback(data, field) : data;
66 66 nbItems = 0;
67 67 $.each(items, function(i, element) {
68 68 var group, text, value;
2  lib/ajax-chosen.min.js
@@ -7,7 +7,7 @@ if(val.length<options.minTermLength){return false;}
7 7 field=$(this);if(options.data==null){options.data={};}
8 8 options.data[options.jsonTermKey]=val;if(options.dataCallback!=null){options.data=options.dataCallback(options.data);}
9 9 success=options.success;options.success=function(data){var items,nbItems,selected_values;if(data==null){return;}
10   -selected_values=[];select.find('option').each(function(){if($(this).not(":selected")){return $(this).remove();}else{return selected_values.push($(this).val()+"-"+$(this).text());}});select.find('optgroup:empty').each(function(){return $(this).remove();});items=callback!=null?callback(data):data;nbItems=0;$.each(items,function(i,element){var group,text,value;nbItems++;if(element.group){group=select.find("optgroup[label='"+element.text+"']");if(!group.size()){group=$("<optgroup />");}
  10 +selected_values=[];select.find('option').each(function(){if($(this).not(":selected")){return $(this).remove();}else{return selected_values.push($(this).val()+"-"+$(this).text());}});select.find('optgroup:empty').each(function(){return $(this).remove();});items=callback!=null?callback(data,field):data;nbItems=0;$.each(items,function(i,element){var group,text,value;nbItems++;if(element.group){group=select.find("optgroup[label='"+element.text+"']");if(!group.size()){group=$("<optgroup />");}
11 11 group.attr('label',element.text).appendTo(select);return $.each(element.items,function(i,element){var text,value;if(typeof element==="string"){value=i;text=element;}else{value=element.value;text=element.text;}
12 12 if($.inArray(value+"-"+text,selected_values)===-1){return $("<option />").attr('value',value).html(text).appendTo(group);}});}else{if(typeof element==="string"){value=i;text=element;}else{value=element.value;text=element.text;}
13 13 if($.inArray(value+"-"+text,selected_values)===-1){return $("<option />").attr('value',value).html(text).appendTo(select);}}});if(nbItems){select.trigger("liszt:updated");}else{select.data().chosen.no_results_clear();select.data().chosen.no_results(field.val());}
2  src/ajax-chosen.coffee
@@ -91,7 +91,7 @@ do ($ = jQuery) ->
91 91
92 92 # Send the ajax results to the user callback so we can get an object of
93 93 # value => text pairs to inject as <option> elements.
94   - items = if callback? then callback(data) else data
  94 + items = if callback? then callback(data, field) else data
95 95
96 96
97 97 nbItems = 0

0 comments on commit 5595836

Please sign in to comment.
Something went wrong with that request. Please try again.