1jQuery(document).ready(function($) { 2 //console.log('[Child Repeater] Initializing validation and conditionals'); 3 4 // Hide both fields by default on page load - AFTER a delay to let repeater render 5 setTimeout(function() { 6 $('select[name^="child-bleeding-disorders"]').each(function() { 7 $(this).closest('span').prev('label').hide(); 8 $(this).closest('span').hide(); 9 }); 10 $('select[name^="child-carrier-types"]').each(function() { 11 $(this).closest('span').prev('label').hide(); 12 $(this).closest('span').hide(); 13 }); 14 //console.log('[Child Repeater] Hidden fields on load'); 15 }, 500); 16 //console.log('[Child Repeater] Hidden fields on load'); 17 18 // Handle show/hide for bleeding disorders and carrier types 19 $(document).on('change', 'input[name^="child-disorder-or-carrier"]', function() { 20 //console.log('[Child Repeater] Checkbox changed'); 21 22 var $checkbox = $(this); 23 var value = $checkbox.val(); 24 var isChecked = $checkbox.is(':checked'); 25 26 var fieldName = $checkbox.attr('name'); 27 var matches = fieldName.match(/child-disorder-or-carrier-(\d+)-(\d+)/); 28 29 if (!matches) { 30 //console.log('[Child Repeater] Could not parse field name:', fieldName); 31 return; 32 } 33 34 var gid = matches[1]; 35 var index = matches[2]; 36 var suffix = gid + '-' + index; 37 38 //console.log('[Child Repeater] GID:', gid, 'Index:', index, 'Value:', value, 'Checked:', isChecked); 39 40 if (value === "They have a Bleeding Disorder") { 41 var $disorderSelect = $('select[name="child-bleeding-disorders-' + suffix + '[]"]'); 42 var $disorderSpan = $disorderSelect.closest('span'); 43 var $disorderLabel = $disorderSpan.prev('label'); 44 45 //console.log('[Child Repeater] Disorder - Select:', $disorderSelect.length, 'Span:', $disorderSpan.length, 'Label:', $disorderLabel.length); 46 47 if (isChecked) { 48 $disorderLabel.show(); 49 $disorderSpan.show(); 50 //console.log('[Child Repeater] Showing bleeding disorders for', suffix); 51 } else { 52 $disorderLabel.hide(); 53 $disorderSpan.hide(); 54 //console.log('[Child Repeater] Hiding bleeding disorders for', suffix); 55 } 56 } else if (value === "They are a Carrier") { 57 var $carrierSelect = $('select[name="child-carrier-types-' + suffix + '[]"]'); 58 var $carrierSpan = $carrierSelect.closest('span'); 59 var $carrierLabel = $carrierSpan.prev('label'); 60 61 //console.log('[Child Repeater] Carrier - Select:', $carrierSelect.length, 'Span:', $carrierSpan.length, 'Label:', $carrierLabel.length); 62 63 if (isChecked) { 64 $carrierLabel.show(); 65 $carrierSpan.show(); 66 //console.log('[Child Repeater] Showing carrier t
66ypes for', suffix); 67 } else { 68 $carrierLabel.hide(); 69 $carrierSpan.hide(); 70 //console.log('[Child Repeater] Hiding carrier types for', suffix); 71 } 72 } 73 }); 74 75 setTimeout(function() { 76 $('input[name^="child-disorder-or-carrier"]:checked').each(function() { 77 $(this).trigger('change'); 78 }); 79 }, 500); 80 81 // Hide fields when new child is added 82 $(document).on('click', '.wpcf7-repeater-add', function() { 83 setTimeout(function() { 84 $('select[name^="child-bleeding-disorders"]').each(function() { 85 $(this).closest('span').prev('label').hide(); 86 $(this).closest('span').hide(); 87 }); 88 $('select[name^="child-carrier-types"]').each(function() { 89 $(this).closest('span').prev('label').hide(); 90 $(this).closest('span').hide(); 91 }); 92 //console.log('[Child Repeater] Hidden new child fields'); 93 }, 100); 94 }); 95 96 $(document).on('click', '.wpcf7-submit', function(e) { 97 var hasError = false; 98 var errorMessages = []; 99 100 // Check if user said they have children 101 var hasChildren = $('input[name="has-children"]:checked').val(); 102 if (hasChildren !== 'Yes') { 103 // Skip child validation if they don't have children 104 return true; 105 } 106 107 $('.wpcf7-repeater-item').each(function(index) { 108 var $group = $(this); 109 var groupNum = index + 1; 110 111 var $disorderCheckbox = $group.find('input[name^="child-disorder-or-carrier"][value="They have a Bleeding Disorder"]'); 112 var $carrierCheckbox = $group.find('input[name^="child-disorder-or-carrier"][value="They are a Carrier"]'); 113 114 var disorderChecked = $disorderCheckbox.is(':checked'); 115 var carrierChecked = $carrierCheckbox.is(':checked'); 116 117 if (disorderChecked) { 118 var $disorderField = $group.find('select[name^="child-bleeding-disorders"]'); 119 var disorderValue = $disorderField.val(); 120 121 if (!disorderValue || disorderValue.length === 0) { 122 hasError = true; 123 errorMessages.push('Child ' + groupNum + ': Please select at least one bleeding disorder'); 124 $disorderField.addClass('wpcf7-not-valid'); 125 } else { 126 $disorderField.removeClass('wpcf7-not-valid'); 127 } 128 } 129 130 if (carrierChecked) { 131 var $carrierField = $group.find('select[name^="child-carrier-types"]'); 132 var carrierValue = $carrierField.val(); 133 134 if (!carrierValue || carrierValue.length === 0) { 135 hasError = true; 136 errorMessages.push('Child ' + groupNum + ': Please select at least one carrier type'); 137 $carrierField.addClass('wpcf7-not-valid'); 138 } else { 139 $carrierField.removeClass('wpcf7-not-valid'); 140 } 141 } 142 143 if (!disorderChecked && !carrierChecked) { 144 hasError = true; 145 errorMessages.push('Child ' + groupNum + ': Please select either "They have a Bleeding Disorder" or "They are a Carrier"'); 146 $disorderCheckbox.closest('p').addClass('wpcf7-not-valid'); 147 } else { 148 $disorderCheckbox.closest('p').removeClass('wpcf7-not-valid'); 149 } 150 }); 151 152 // Validate all required child fields 153 $('.wpcf7-repeater-item').each(function(index) { 154 var $group = $(this); 155 var groupNum = index + 1; 156 157 var requiredFields = [ 158 {selector: 'input[name^="childs-first-name"]', label: "Child's first name"}, 159 {selector: 'input[name^="childs-last-name"]', label: "Child's last name"}, 160 {selector: 'input[name^="childs-dob"]', label: "Child's date of birth"}, 161 {selector: 'select[name^="childs-sex_at_birth"]', label: "Child's sex at birth"}, 162 {selector: 'select[name^="child-ethnicity"]', label: "Child's ethnic group"}, 163 {selector: 'select[name^="child-language-preference"]', label: "Child's language preference"}, 164 {selector: 'select[name^="child-ethnicity-group"]', label: "Child's nationality group"}, 165 {selector: 'input[name^="child-date-of-diagnosis"]', label: "Date of diagnosis"}, 166 {selector: 'select[name^="child-haemophilia-center"]', label: "Haemophilia centre"} 167 ]; 168 169 requiredFields.forEach(function(field) { 170 var $field = $group.find(field.selector); 171 var value = $field.val(); 172 173 if (!value || value === '') { 174 hasError = true; 175 errorMessages.push('Child ' + groupNum + ': Please complete ' + field.label); 176 $field.addClass('wpcf7-not-valid'); 177 } else { 178 $field.removeClass('wpcf7-not-valid'); 179 } 180 }); 181 }); 182 183 if (hasError) { 184 e.preventDefault(); 185 e.stopPropagation(); 186 alert('Please complete all required child fields:\n\n' + errorMessages.join('\n')); 187 188 return false;
189 } 190 }); 191 192 $(document).on('change', 'input, select', function() { 193 // Clear validation errors when anything changes 194 $('select[name^="child-bleeding-disorders"], select[name^="child-carrier-types"]').removeClass('wpcf7-not-valid'); 195 $('input[name^="child-disorder-or-carrier"]').closest('p').removeClass('wpcf7-not-valid'); 196 }); 197 198 //console.log('[Child Repeater] Validation ready'); 199});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.