Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // setup required fields. Variables set as:
- // initial_question, followup_question
- // Note: This has not been tested with Ajax enabled, so it still requires
- // a check on the server side.
- //
- var $q8 = jQuery('li#field_2_16'), $q9 = jQuery('li#field_2_25'),
- $q10 = jQuery('li#field_2_18'), $q11 = jQuery('li#field_2_30'),
- $q12 = jQuery('li#field_2_20'), $q13 = jQuery('li#field_2_21'),
- $q14 = jQuery('li#field_2_22'), $q15 = jQuery('li#field_2_23'),
- requiredAsterisk = '<span class="gfield_required">*</span>';
- //
- // check for change in field, and mark updateField required if triggerChoice is checked
- //
- function checkField(triggerChoice, $updateField) {
- // check to see if the triggerChoice input is checked
- if ( jQuery(triggerChoice).attr("checked") === 'checked' ) { // is checked
- // mark the updateField as required if it isn't already
- if ( $updateField.find("span.gfield_required").length == 0 ) {
- $updateField.find("label").eq(0).append(requiredAsterisk);
- }
- }
- else { // not checked
- // we remove the required asterisk since the trigger is not set
- $updateField.find("span.gfield_required").remove();
- }
- return;
- }
- //
- // this looks for a change on the initial question's input field
- // once its found, it calls the checkField function. It takes two fields:
- //
- // triggerChoice : the selector for the input field of the option/choice in
- // the initial question that makes the followup question now required
- //
- // $updateField : This is the field will get updated and set as required if triggerChoice
- // is checked.
- //
- $q8.find('input').on('change', function() { checkField('input#choice_16_1', $q9); } );
- $q10.find('input').on('change', function() { checkField('input#choice_18_1', $q11); } );
- $q12.find('input').on('change', function() { checkField('input#choice_20_4', $q13); } );
- $q14.find('input').on('change', function() { checkField('input#choice_22_4', $q15); } );
- //
- // Since the fields might still be required after an attempted page submit, we do a check once the page
- // has loaded, these checkField calls are identical to the ones in the four lines above.
- //
- checkField('input#choice_16_1', $q9);
- checkField('input#choice_18_1', $q11);
- checkField('input#choice_20_4', $q13);
- checkField('input#choice_22_4', $q15);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement