diff --git a/lib/ajax-chosen.js b/lib/ajax-chosen.js index c9e3123..64b5c5e 100644 --- a/lib/ajax-chosen.js +++ b/lib/ajax-chosen.js @@ -21,12 +21,13 @@ options = $.extend({}, defaultOptions, $(select).data(), settings); this.chosen(chosenOptions ? chosenOptions : {}); return this.each(function() { + var $this = $(this); return $(this).next('.chzn-container').find(".search-field > input, .chzn-search > input").bind('keyup', function() { var field, msg, success, untrimmed_val, val; untrimmed_val = $(this).val(); val = $.trim($(this).val()); msg = val.length < options.minTermLength ? options.keepTypingMsg : options.lookingForMsg + (" '" + val + "'"); - select.next('.chzn-container').find('.no-results').text(msg); + $this.next('.chzn-container').find('.no-results').text(msg); if (val === $(this).data('prevVal')) { return false; } @@ -52,14 +53,14 @@ return; } selected_values = []; - select.find('option').each(function() { + $this.find('option').each(function() { if (!$(this).is(":selected")) { return $(this).remove(); } else { return selected_values.push($(this).val() + "-" + $(this).text()); } }); - select.find('optgroup:empty').each(function() { + $this.find('optgroup:empty').each(function() { return $(this).remove(); }); items = callback != null ? callback(data, field) : data; @@ -68,11 +69,11 @@ var group, text, value; nbItems++; if (element.group) { - group = select.find("optgroup[label='" + element.text + "']"); + group = $this.find("optgroup[label='" + element.text + "']"); if (!group.size()) { group = $(""); } - group.attr('label', element.text).appendTo(select); + group.attr('label', element.text).appendTo($this); return $.each(element.items, function(i, element) { var text, value; if (typeof element === "string") { @@ -95,15 +96,15 @@ text = element.text; } if ($.inArray(value + "-" + text, selected_values) === -1) { - return $("