Skip to content
Snippets Groups Projects
Select Git revision
  • a02f9f337a3f4460765ffcdb192d4a0a00df714d
  • master default
2 results

stuapp.js

Blame
  • stuapp.js 11.22 KiB
    /*
    	2011 updated JS
    */
    
    WDN.jQuery('document').ready(function($){
        // for IE, we need to add a class to support the two columns 
        $('#maincontent .stuapp > fieldset > ol > li:nth-child(odd)').addClass('odd');
        
        // for older browsers, we need to use a span to control the width of the legends to prevent overflows.
        $('form.stuapp legend').each(function() {
    		$(this).wrapInner('<span />');
    	});
        
        /*
         * Show/Hide of aside content
         */
        $('aside').each(function(){
        	$(this).children('h4:first-child').nextAll().wrapAll('<div class="toggledContent">');
        	$(this).children('h4:first-child').after('<a href="#" class="showHide">show/hide this</a>');
        });
        $('aside .showHide').click(function(){
        	$(this).siblings('.toggledContent').slideToggle(function() {
    			$(this).siblings('a.showHide').toggleClass('show');
    		});
    		return false;
        });
        $('aside a.showHide').click();
        
        /*
         * For layout, we need to add a shim to keep the asides from floating all the way up in IE
         */
        $('.stuapp > fieldset, .stuapp input[type="submit"]').before('<div class="grid12" />');
        /*
        *
        * Form Validation Stuff
        *
        */
        
        // hide each of the areas which don't need to be present by default
        $.each(hiddenAreas, function(i,v){
            $(v).hide().attr({'aria-expanded' : 'false'});
        });
        
        //add aria-contols attributes where we show/hide content
        $('input[name="prof_in_english"]').attr({'aria-controls' : 'native_lang'});
        $('input[name="perm_res"]').attr({'aria-controls' : 'non-us'});
        $('input[name="res_stat"]').attr({'aria-controls' : 'date_ranges'});
        
        
        // add appropriate classes to the form elements
        // http://www1.unl.edu/wdn/wiki/JQuery_Validation
        // kabel's suggestion for IE support
        $.expr[":"]["required"] = function( elem ) {
            elem.required === true;
        };
        // the current HTML5 spec for required is not as user-friendly as JS alternatives, so we'll yank these out.
        $('.stuapp *[required]').addClass('required-entry').removeAttr('required');
        //$('.stuapp *:required').addClass('required-entry').removeAttr('required');
        $('#email').addClass('validate-email');
        $('#parentZip, #zip').addClass('validate-zip');
        $('#ssn1').addClass('validate-digits');
        $('input[type="radio"]').removeClass('required-entry').addClass('validate-one-required-by-name');
        
        // specific actions
        
        // short-circuit the validation if special code is added to field
        $('#lastName').change(function() {
            if($(this).val() == 'justtesting') {
                $('.required-entry, .validate-one-required-by-name, .validate-one-required').removeClass('required-entry validate-one-required-by-name validate-one-required');
                $('.required').removeClass('required');
            }
        });
        
        // user has indicated parent's are are same address, so pre-fill
        $('#parentSameYes').change(function(){
            $('#parentStreet1').val($('#street').val());
            $('#parentStreet2').val($('#street2').val());
            $('#parentCity').val($('#city').val());
            $('#parentProvince').val($('#province').val());
            $('#parentCountry').val($('#country').val());
            $('#parentState').val($('#state').val());
            $('#parentZip').val($('#zip').val());
        });
        
        // if a value changes in the parent information, set the student's radio button
        $('#parentInformation input, #parentInformation select').change(function(){
            $('#parentSameNo').not('#parentName').not('#parentPhone').prop('checked', true);
        });
        
        //For some reason, we're updating a hidden field with the value used in a radio??
        $('input[name="gender"]').change(function(){
            $('input[name="Gender"]').val($(this).val());
        });
        
        // if a NE resident, show options
        $('#resident').change(function() {
            $('#date_ranges').show().attr({'aria-expanded' : 'true'});
            $('#date_ranges input').addClass('required-entry').eq(0).focus();
            $('#date_ranges label').addClass('required');
        });
        // if a NE resident, show options
        $('#nonresident').change(function() {
            $('#date_ranges').hide().attr({'aria-expanded' : 'false'});
            $('#date_ranges input').removeClass('required-entry').eq(0).focus();
            $('#date_ranges label').removeClass('required');
        });
        
        // if non-US citizen, show options
        $('#citizenshipPermRes').change(function() {
            $('#non-us').show().attr({'aria-expanded' : 'true'});
            $('#citizenCountry').val('');
            $('#non-us input, #non-us select').not('#birthCountryOther').addClass('required-entry').eq(0).focus();
            $('#non-us label').not('label[for="birthCountryOther"]').addClass('required');
            $('input[name="citizenflag"]').val('Y');
            $('#ssn1').removeClass('required-entry');
        });
        $('#citizenshipOther').change(function() {
            $('#non-us').show().attr({'aria-expanded' : 'true'});
            $('#citizenCountry').val('');
            $('#non-us input, #non-us select').not('#birthCountryOther').addClass('required-entry').eq(0).focus();
            $('#non-us label').not('label[for="birthCountryOther"]').addClass('required');
            $('input[name="citizenflag"]').val('0');
            $('#ssn1').removeClass('required-entry');
        });
        $('#citizenshipUS').change(function(){
            $('#citizenCountry').val('USA');
            $('#non-us').hide().attr({'aria-expanded' : 'false'});
            $('#non-us input, #non-us select').removeClass('required-entry');
            $('#non-us label').removeClass('required');
            $('input[name="citizenflag"]').val('U');
            $('#ssn1').addClass('required-entry');
        });
        
        $('#englishLangYes').change(function(){
            $('input[name="English_as_First_Lang"]').val('Y');
            $('#native_lang').hide().attr({'aria-expanded' : 'false'});
            $('#native_lang input').removeClass('required-entry');
            $('#native_lang label').removeClass('required');
        });
        $('#englishLangNo').change(function(){
            $('input[name="English_as_First_Lang"]').val('N');
            $('#native_lang').show().attr({'aria-expanded' : 'true'});
            $('#native_lang input').addClass('required-entry').eq(0).focus();
            $('#native_lang label').addClass('required');
        });
        
        $('#currentEnrollClgYes').change(function(){
        	$('input[name="Current_Enrolled_Elsewhere"]').val('Y');
        	$('#current_college').show().attr({'aria-expanded' : 'true'});
        	$('#current_college input').addClass('required-entry').eq(0).focus();
        	$('#current_college label').addClass('required');
        });
        $('#currentEnrollClgNo').change(function(){
        	$('input[name="Current_Enrolled_Elsewhere"]').val('N');
        	$('#current_college').hide().attr({'aria-expanded' : 'false'});
        	$('#current_college input').removeClass('required-entry');
        	$('#current_college label').removeClass('required');
        });
    
        $('#familyAlumniYes').change(function(){
        	$('#family_alums').show().attr({'aria-expanded' : 'true'});
        	$('#family_alums input[type="text"]').addClass('required-entry').eq(0).focus();
        	$('#family_alums legend').addClass('required');
        });
        $('#familyAlumniNo').change(function(){
        	$('#family_alums').hide().attr({'aria-expanded' : 'false'});
        	$('#family_alums input[type="text"]').removeClass('required-entry');
        	$('#family_alums legend').removeClass('required');
        });
    
        $('#bachelorsYes').change(function(){
        	$('input[name="Received_Bachelors"]').val('Y');
        	$('#bc_college, #bc_college_info, #bc_alert').show().attr({'aria-expanded' : 'true'});
        	$('#bc_college input[type="text"]').addClass('required-entry').eq(0).focus();
        	$('#bc_college label').addClass('required');
        });
        $('#bachelorsNo').change(function(){
        	$('input[name="Received_Bachelors"]').val('N');
        	$('#bc_college, #bc_college_info, #bc_alert').hide().attr({'aria-expanded' : 'false'});
        	$('#bc_college input[type="text"]').removeClass('required-entry');
        	$('#bc_college label').removeClass('required');
        });
        
        $('#americanIndian').click(function(){
        	if($(this).is(':checked')){
        		$('#tribalInput').show().attr({'aria-expanded' : 'true'});
        	} else {
        		$('#tribalInput').hide().attr({'aria-expanded' : 'false'});
        	}
        });
    
        $('#persStmntYes').change(function(){
        	$('#personal_statement_wrapper').show().attr({'aria-expanded' : 'true'}).find('textarea').focus();
        });
        
        $('#persStmntNo').change(function(){
        	$('#personal_statement_wrapper').hide().attr({'aria-expanded' : 'false'});
        });
        
        $('#application_fee input').change(function(){
        	$('input[name="Application_Fee"]').val($(this).val());
        	$('label[for="feeWaiver"] + p').remove();
    	    if ($(this).val() == "WV"){
    			$('#system_school').html(
    				  '<label for="Previously_Attended_Campus">Select the campus attended/applied<label>'
    				+ '<select name="Previously_Attended_Campus" id="Previously_Attended_Campus" class="required" >'
    		  		+ '  <option value="" ></option>'
    				+ '  <option value="UK">University of Nebraska-Kearney</option>'
    				+ '  <option value="UO">University of Nebraska-Omaha</option>'
    				+ '  <option value="WV">University of Nebraska-Lincoln</option>'
    				+ '  <option value="UM">University of Nebraska-Medical Center</option>'
    				+ '</select>'
    				+ '<fieldset>'
    				+ '<legend class="required">What date did you pay your application fee?</legend>'
    				+ '<fieldset class="date_range_set tri"><legend>Date Range (mm/dd/yyyy)</legend>'
    				+ '<div><label for="Previously_Attended_month">Month</label><input type="text" name="Previously_Attended_month" id="Previously_Attended_month" value="" maxlength="2"  onchange="validDateMonth(this);" /></div>'
    				+ '<div><label for="Previously_Attended_day">Day</label><input type="text" name="Previously_Attended_day" id="Previously_Attended_day" value=""  maxlength="2" onchange="validDateDay(this);" /></div>'
    				+ '<div><label for="Previously_Attended_year">Year</label><input type="text" name="Previously_Attended_year" id="Previously_Attended_year" value="" maxlength="4" onchange="validDateYear(this);" /></div>'
    	   			+ '</fieldset> '
    			).show();
    		}
    	    else if($(this).val() == "ND") {
    	    	$('label[for="feeWaiver"]').after(
    	    		'<p>Students are only considered for a fee waiver if they qualify for the free or reduced school lunch program OR if they have been granted a waiver on the ACT or SAT test.  Documentation for these programs should be submitted with the application materials.</p>'
    	    	);
    	    }
    		else {
    			$('#system_school').html(" " +
    				+ '<input type="hidden" name="Previously_Attended_Campus"> '
    				+ '<input type="hidden" name="Previously_Attended_month"> '
    				+ '<input type="hidden" name="Previously_Attended_day"> '
    				+ '<input type="hidden" name="Previously_Attended_year"> '
    			).hide();
    		}
        });
        
        // The form validation places the helper at the bottom of the input's parent element. This doesn't work quite right for input siblings, so we'll have to wrap some of them.
        $('select, input').each(function(){
            if($(this).next('label').length > 0){
            	$(this).wrap('<div/>');
            }
        });
        
        WDN.loadCSS('/wdn/templates_3.0/css/content/formvalidator.css');
        WDN.loadJS('/wdn/templates_3.0/scripts/plugins/validator/jquery.validator.js', function() {
            $('form.stuapp').validation({
        	    'immediate' : true
        	});
        });
    });