Skip to content
Browse files

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

  • Loading branch information...
1 parent fc38852 commit 55958361ff85baafad6fb8e9caad6aa58c060676 @fredwu fredwu committed Feb 8, 2013
Showing with 3 additions and 3 deletions.
  1. +1 −1 lib/ajax-chosen.js
  2. +1 −1 lib/ajax-chosen.min.js
  3. +1 −1 src/ajax-chosen.coffee
View
2 lib/ajax-chosen.js
@@ -62,7 +62,7 @@
select.find('optgroup:empty').each(function() {
return $(this).remove();
});
- items = callback != null ? callback(data) : data;
+ items = callback != null ? callback(data, field) : data;
nbItems = 0;
$.each(items, function(i, element) {
var group, text, value;
View
2 lib/ajax-chosen.min.js
@@ -7,7 +7,7 @@ if(val.length<options.minTermLength){return false;}
field=$(this);if(options.data==null){options.data={};}
options.data[options.jsonTermKey]=val;if(options.dataCallback!=null){options.data=options.dataCallback(options.data);}
success=options.success;options.success=function(data){var items,nbItems,selected_values;if(data==null){return;}
-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 />");}
+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 />");}
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;}
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;}
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());}
View
2 src/ajax-chosen.coffee
@@ -91,7 +91,7 @@ do ($ = jQuery) ->
# Send the ajax results to the user callback so we can get an object of
# value => text pairs to inject as <option> elements.
- items = if callback? then callback(data) else data
+ items = if callback? then callback(data, field) else data
nbItems = 0

0 comments on commit 5595836

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