Created
July 13, 2013 21:35
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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