1// stores the currently active sub fields 2if (activeWebformSubFields == null) { 3 var activeWebformSubFields = new Array(); 4} 5 6// stores the mapping of parent field name, chosen parent value and sub field set ID 7if (webFormSubFieldMappings == null) { 8 var webFormSubFieldMappings = new Array(); 9} 10 11// initializes the visible sub fields 12function initWebformSubFields(formID) { 13 const form = document.getElementById(formID); 14 const fields = form.querySelectorAll("input, select"); 15 fields.forEach(field => { 16 if (field.dataset.subfields === "true") { 17 toggleWebformSubFields(field); 18 } 19 }); 20} 21 22// toggles the sub field visibility depending on the field value 23function toggleWebformSubFields(inputField) { 24 if (inputField.type === "radio" && !inputField.checked) { 25 return; 26 } 27 var subIDToShow = getWebFomSubField(inputField.name, inputField.value); 28 var activeID = getActiveWebFormSubField(inputField.name); 29 if (activeID != "" && subIDToShow != activeID) { 30 // deactivate currently active sub fields 31 document.getElementById(activeID).style.display = "none"; 32 toggleDisableWebFormSubFields(activeID, true); 33 } 34 if (subIDToShow != "") { 35 // set to empty String otherwise FF does not display anything... 36 document.getElementById(subIDToShow).style.display = ""; 37 toggleDisableWebFormSubFields(subIDToShow, false); 38 } 39 setActiveWebformSubField(inputField.name, subIDToShow); 40} 41 42// stores the active sub fields for the field name 43function setActiveWebformSubField(fieldName, subID) { 44 var found = false; 45 for (var i = 0; i < activeWebformSubFields.length; i++) { 46 if (activeWebformSubFields[i].fieldName == fieldName) { 47 // found existing entry, update it 48 activeWebformSubFields[i].subID = subID; 49 found = true; 50 break; 51 } 52 } 53 if (!found && subID != "") { 54 // no active item listed for field, create new entry 55 var arrIndex = activeWebformSubFields.length; 56 activeWebformSubFields[arrIndex] = new Object(); 57 activeWebformSubFields[arrIndex].fieldName = fieldName; 58 activeWebformSubFields[arrIndex].subID = subID; 59 } 60} 61 62// returns the active sub field ID for the given field 63function getActiveWebFormSubField(fieldName) { 64 // iterate all active entries 65 for (var i = 0; i < activeWebformSubFields.length; i++) { 66 if (activeWebformSubFields[i].fieldName == fieldName) { 67 // found entry, return currently active sub ID 68 return activeWebformSubFields[i].subID; 69 } 70 } 71 // nothing found, return empty String 72 return ""; 73} 74 75// adds a web form sub field mapping 76function addWebFormSubFieldMapping(parentFieldName, parentFieldValue, subID) { 77 var arrIndex = webFormSubFieldMappings.length; 78 webFormSubFieldMappings[arrIndex] = new Object(); 79 webFormSubFieldMappings[arrIndex].parentFieldName = parentFieldName; 80 webFormSubFieldMappings[arrIndex].parentFieldValue = parentFieldValue; 81 webFormSubFieldMappings[arrIndex].subID = subID; 82 toggleDisableWebFormSubFields(subID, true); 83} 84 85// diables/enables subfields depending on their visibility 86function toggleDisableWebFormSubFields(subID, disable) { 87 const fields = document.getElementById(subID).querySelectorAll("input, select, textarea"); 88 fields.forEach(field => { 89 field.disabled = disable; 90 }); 91} 92 93// returns the sub field ID to activate for the given parent field name and value 94function getWebFomSubField(parentFieldName, parentFieldValue) { 95 for (var i = 0; i < webFormSubFieldMappings.length; i++) { 96 if (webFormSubFieldMappings[i].parentFieldName == parentFieldName 97 && webFormSubFieldMappings[i].parentFieldValue == parentFieldValue) { 98 return webFormSubFieldMappings[i].subID; 99 } 100 } 101 return ""; 102}
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.