Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Related Selects + Chosen #11

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/jquery.relatedselects.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
}

// make array of select names
$.each(opts.selects, function(){
$.each(opts.selects, function(key){
selects.push(key);
});

Expand Down Expand Up @@ -87,14 +87,14 @@
if(value.length > 0 && value !== o.loadingMessage && $next){

// reset all selects after this one
resetAfter(elem);
resetAfter(elem,o);

// populate the next select
populate($select,$next,o);

// otherwise, make all the selects after this one disabled and select the first option
} else if($next){
resetAfter(elem);
resetAfter(elem,o);
}
}

Expand Down Expand Up @@ -132,7 +132,8 @@

// build the options
$.each(data, function(i,item){
html.push('<option value="'+i+'">' + item + '</option>');
var isObj = typeof(item) == 'object';
html.push('<option value="'+(isObj?item.value:i)+'">' + (isObj?item.text:item) + '</option>');
});

$select.html( html.join('') ).removeAttr('disabled');
Expand All @@ -157,10 +158,11 @@
return (options.length === 0 || (options.length === 1 && options.filter(':first').attr('value').length === 0)) ? false : true;
}

function resetAfter(elem){
function resetAfter(elem,o){
var thispos = getPosition(elem);
for (var x=thispos+1, len=selects.length; x<len; x++){
$("select[name='" + selects[x] + "']", $context ).attr('disabled','disabled').find('option:first').attr('selected','selected');
var $select = $("select[name='" + selects[x] + "']", $context ).attr('disabled','disabled').find('option:first').attr('selected','selected').trigger('change');
o.onAfterReset.call($select);
}
}

Expand Down Expand Up @@ -196,7 +198,8 @@
onLoadingStart: function(){},
onLoadingEnd: function(){},
onChange: function(){},
onEmptyResult: function(){}
onEmptyResult: function(){},
onAfterReset: function(){}
};

})(jQuery);
Expand Down