Skip to content

Instantly share code, notes, and snippets.

@EdwardIrby
Created July 13, 2013 21:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EdwardIrby/5992307 to your computer and use it in GitHub Desktop.
Save EdwardIrby/5992307 to your computer and use it in GitHub Desktop.
Small script that listens for categories selected on the OpenSesame course upload page. It then uses the selected options to reveal radio button options that the user will be required to choose from in order to select a primary category for their course.
var subjects = jQuery('#edit-field-course-subjects-taxonomy-und');
function displayPrimarySubject(){
var subjectVal =[];
var subjectInput = subjects.find('input:checked');
subjectInput.each(function(){
var catVal= jQuery(this).val();
subjectVal.push(catVal);
});
var primarySubjectField= jQuery('#edit-field-primary-subject');
if (subjectVal.length > 0){
primarySubjectField.show();
var primarySubjects = jQuery('#edit-field-primary-subject-und').find('input');
primarySubjects.each(function(){
var selectedSubject = jQuery(this);
var optionVal = jQuery(this).val();
var returnVal = jQuery.inArray(optionVal, subjectVal);
if(returnVal > -1){
console.log(returnVal);
selectedSubject.parent().show();
}else{
selectedSubject.parent().hide();
}
});
} else{
primarySubjectField.hide();
}
}
displayPrimarySubject();
subjects.find('input').click(function(){
displayPrimarySubject();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment