1document.querySelectorAll('.js-add-additional-registration').forEach(el => { 2 el.addEventListener('click', function (e) { 3 e.preventDefault(); 4 5 let index = parseInt(this.getAttribute('data-index')); 6 document.querySelector('.js-event-additional-registration-' + index).classList.remove('hidden'); 7 this.classList.add('hidden'); 8 9 // Enable registration 10 document.querySelector('#js-registration-enabled-' + index).value = '1'; 11 12 // Set amount of registrations 13 document.querySelector('.js-amount-registrations').value = index + 1; 14 }); 15}); 16 17document.querySelectorAll('.js-remove-additional-registration').forEach(el => { 18 el.addEventListener('click', function (e) { 19 e.preventDefault(); 20 21 let index = parseInt(this.getAttribute('data-index')); 22 let amountOfRegistrations = getAmountOfRegistrations(); 23 24 if (index >= 1) { 25 document.querySelector('.js-event-additional-registration-' + index).classList.add('hidden'); 26 document.querySelector('.js-add-additional-registration-' + index).classList.remove('hidden'); 27 28 // Disable registration 29 document.querySelector('#js-registration-enabled-' + index).value = '0'; 30 31 // Set amount of registrations 32 document.querySelector('.js-amount-registrations').value = amountOfRegistrations - 1; 33 } 34 }); 35}); 36 37function getAmountOfRegistrations() { 38 if (!document.querySelector('.js-amount-registrations')) { 39 return 0; 40 } 41 42 return parseInt(document.querySelector('.js-amount-registrations').value); 43} 44 45function isInheritanceField(fieldname, inheritanceFields) { 46 console.log(inheritanceFields); 47 if (fieldname.startsWith('tx_sfeventmgt_pieventregistration[registration][fields]')) { 48 let match = fieldname.match(/\[(\d+)\](?!.*\[\d+\])/); 49 if (match) { 50 return inheritanceFields.registrationFields.includes(Number(match[1])); 51 } 52 } else { 53 let match = fieldname.match(/\[([^\[\]]+)\]$/); 54 if (match) { 55 return inheritanceFields.defaultFields.includes(match[1]); 56 } 57 } 58 59 return false; 60} 61 62document.addEventListener('DOMContentLoaded', () => { 63 let amountOfRegistrations = getAmountOfRegistrations(); 64 // Show additional registrations (e.g. on validation errors) 65 if (amountOfRegistrations > 1) { 66 // Hide first add registration button 67 document.querySelector('.js-add-additional-registration-1').classList.add('hidden'); 68 69 for (let i = 1; i <= (amountOfRegistrations - 1); i++) { 70 document.querySelector('.js-add-additional-registration-' + i).classList.add('hidden'); 71 document.querySelector('.js-event-additional-registration-' + i).classList.remove('hidden'); 72 } 73 } 74 75 let registrationForm = document.querySelector('form[name="registration"]'); 76 let inheritanceFields = JSON.parse(registrationForm.getAttribute('data-inheritance-fields') || '[]'); 77 registrationForm.addEventListener('change', function(event) { 78 let maxRegistrationsPerUser = 1; 79 if (document.getElementById('amountOfRegistrations')) { 80 maxRegistrationsPerUser = parseInt(registrationForm.getAttribute('data-max-registrations-per-user')); 81 } 82 if (maxRegistrationsPerUser <= 1 || !event.target.name.startsWith('tx_sfeventmgt_pieventregistration[registration]')) { 83 return; 84 } 85 86 if (event.target.matches('input, textarea, select') && isInheritanceField(event.target.name, inheritanceFields)) { 87 let targetValue = event.target.value; 88 let fieldName = event.target.name; 89 let isCheckboxOrRadio = event.target.type === 'checkbox' || event.target.type === 'radio'; 90 let targetChecked = event.target.checked; 91 92 for (let i = 1; i <= maxRegistrationsPerUser; i++) { 93 let subFieldName = fieldName.replace( 94 'tx_sfeventmgt_pieventregistration[registration]', 95 `tx_sfeventmgt_pieventregistration[additionalRegistrations][registrations][${i}][registration]` 96 ); 97 let subField = registrationForm.querySelector(`[name="${subFieldName}"]`); 98 99 if (subField) { 100 if (isCheckboxOrRadio) { 101 if (!subField.checked) { 102 subField.checked = targetChecked; 103 } 104 } else { 105 if (subField.value === '') { 106 subField.value = targetValue; 107 } 108 } 109 } 110 } 111 } 112 }); 113});
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.