Skip to content

Commit

Permalink
Merge pull request prashantchaudhary#31 from peterbee/master
Browse files Browse the repository at this point in the history
Thanks! This fixes for multiple selects bug prashantchaudhary#4.
  • Loading branch information
prashantchaudhary committed Jul 12, 2013
2 parents b9a5af0 + 9864669 commit 5c1eca6
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions jquery.ddslick.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@
'.dd-container{ position:relative;}​ .dd-selected-text { font-weight:bold}​</style>';

//Public methods
methods.init = function (options) {
methods.init = function (userOptions) {
//Preserve the original defaults by passing an empty object as the target
//The object is used to get global flags like embedCSS.
var options = $.extend({}, defaults, options);
var options = $.extend({}, defaults, userOptions);

//CSS styles are only added once.
if ($('#css-ddslick').length <= 0 && options.embedCSS) {
Expand All @@ -71,7 +71,7 @@
return this.each(function () {
//Preserve the original defaults by passing an empty object as the target
//The object is used to save drop-down's corresponding settings and data.
var options = $.extend({}, defaults, options);
var options = $.extend({}, defaults, userOptions);

var obj = $(this),
data = obj.data('ddslick');
Expand All @@ -98,15 +98,17 @@
else options.data = $.merge(ddSelect, options.data);

//Replace HTML select with empty placeholder, keep the original
var original = obj, placeholder = $('<div id="' + obj.attr('id') + '"></div>');
var original = obj, placeholder = $('<div').attr('id', obj.attr('id') + '-dd-placeholder');
obj.replaceWith(placeholder);
obj = placeholder;

//Add classes and append ddSelectHtml & ddOptionsHtml to the container
obj.addClass('dd-container').append(ddSelectHtml).append(ddOptionsHtml);

// Inherit name attribute from original element
obj.find("input.dd-selected-value").attr("name", $(original).attr("name"))
obj.find("input.dd-selected-value")
.attr("id", $(original).attr("id"))
.attr("name", $(original).attr("name"));

//Get newly created ddOptions and ddSelect to manipulate
var ddSelect = obj.find('.dd-select'),
Expand Down

0 comments on commit 5c1eca6

Please sign in to comment.