<div class="registration-select-junior registration_hide" data-junior="true">
<div class="registration-personal-details__title">
<div class="registration-form-title">
Who will be joining?
</div>
</div>
<div class="registration-personal-details__sub-title">
<div class="registration-form-sub-title">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do abore et dolore magna aliqexercitation commodo consequat.
</div>
</div>
<div class="registration-error registration-server-error registration_hide" role="alert">
<span class="registration-error-message">sitecore api error</span>
</div>
<div class="registration-select-junior_list-container">
<div class="registration-select-junior__selectAll-container">
<a href="/" class="registration-select-junior__selectAll">Select all</a>
</div>
<div class="registration-select-junior_list">
<label class="checkbox checkbox--with-dob">
<input type="checkbox" data-fan="67890" name="junior1" data-name="Ram" data-individual-id="RAMA">
<div class="dob-label-container">
<span class="label">Will Young</span>
<p class="dob-label">DOB:08/08/1995</p>
</div>
<span class="checkmark-container">
<span class="checkmark"></span>
</span>
</label>
<label class="checkbox checkbox--with-dob">
<input type="checkbox" data-fan="98765" name="junior2" data-name="Ravan" data-individual-id="RAVANA">
<div class="dob-label-container">
<span class="label">Gareth Gates</span>
<p class="dob-label">DOB:08/08/1995</p>
</div>
<span class="checkmark-container">
<span class="checkmark"></span>
</span>
</label>
<label class="checkbox checkbox--with-dob">
<input type="checkbox" data-fan="67890" name="junior1" data-name="Ram" data-individual-id="RAMA">
<div class="dob-label-container">
<span class="label">Will Young</span>
<p class="dob-label">DOB:08/08/1995</p>
</div>
<span class="checkmark-container">
<span class="checkmark"></span>
</span>
</label>
<label class="checkbox checkbox--with-dob">
<input type="checkbox" data-fan="98765" name="junior2" data-name="Ravan" data-individual-id="RAVANA">
<div class="dob-label-container">
<span class="label">Gareth Gates</span>
<p class="dob-label">DOB:08/08/1995</p>
</div>
<span class="checkmark-container">
<span class="checkmark"></span>
</span>
</label>
<label class="checkbox checkbox--with-dob">
<input type="checkbox" data-fan="98765" name="junior2" data-name="Ravan" data-individual-id="RAVANA">
<div class="dob-label-container">
<span class="label">Gareth Gates</span>
<p class="dob-label">DOB:08/08/1995</p>
</div>
<span class="checkmark-container">
<span class="checkmark"></span>
</span>
</label>
</div>
</div>
<div class="cta-container">
<div class="registration-select-junior__next">
<a href="/" class="cta cta--r-disabled " id="btnTakePhoto">
<p>NEXT</p>
</a>
</div>
<div class="registration-select-junior__add">
<a href="/" class="cta cta--r-disabled " id="btnTakePhoto">
<p>Add New</p>
</a>
</div>
</div>
</div>
No notes defined.
{
"title": {
"copy": "Who will be joining?"
},
"sub-title": {
"copy": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do abore et dolore magna aliqexercitation commodo consequat."
},
"next": {
"copy": "NEXT",
"id": "btnTakePhoto"
},
"new": {
"copy": "Add New",
"id": "btnTakePhoto"
},
"junior1": {
"copy": "Will Young",
"name": "junior1",
"fan": "67890",
"username": "Ram",
"individualId": "RAMA",
"dob": "DOB:08/08/1995"
},
"junior2": {
"copy": "Gareth Gates",
"name": "junior2",
"fan": "98765",
"username": "Ravan",
"individualId": "RAVANA",
"dob": "DOB:08/08/1995"
}
}
/* eslint-disable compat/compat */
import {
cloneElement,
currentPage,
hideStep,
nevigateToNext,
onComponentVisible,
setText,
showBackBtn,
} from '../../registrationUtility';
import Validator from '../../validation';
import registrationUploadPassport from '../registration-upload-passport/registration-upload-passport';
import registrationPassportDetails from '../registration-passport-details/registration-passport-details';
// eslint-disable-next-line import/no-named-as-default, import/no-named-as-default-member
import registrationUploadProfile from '../registration-upload-profile/registration-upload-profile';
import { hideClass } from '../../registration-error/registration-error';
export default (currentElement, newRegisreation) => {
let controller = new AbortController();
const getSelectedJuniors = checkboxes => {
const selectJuniors = [];
checkboxes.forEach(checkBox => {
if (checkBox.checked) {
selectJuniors.push({
name: checkBox.getAttribute('data-name'),
fan: checkBox.getAttribute('data-fan'),
individualid: checkBox.getAttribute('data-individual-id'),
});
}
});
currentPage.selectJuniors = selectJuniors;
return selectJuniors;
};
const checBoxCheckHandler = (checkboxes, nextBtn) => {
if (checkboxes.length) {
const selectedJuniors = getSelectedJuniors(checkboxes);
Validator.swaapBtn(nextBtn, selectedJuniors.length);
}
};
const selectAllClickHandler = (event, checkboxes, nextBtn) => {
event.preventDefault();
checkboxes.forEach(checkbox => {
// eslint-disable-next-line no-param-reassign
checkbox.checked = true;
});
checBoxCheckHandler(checkboxes, nextBtn);
};
const removePreviousNodes = parentNode => {
const { children } = parentNode;
for (let index = 1; index < children.length; index++) {
children[index].classList.add('registration_skip');
}
};
const modifyElement = (clonedElement, elementSelector, fan) => {
const modifiedElement = clonedElement;
const [
titleElement,
subTitleElement,
selectedElement,
] = modifiedElement.querySelectorAll(
`.registration-form-title, .registration-form-sub-title, ${elementSelector}`
);
if (
modifiedElement.classList.contains('registration-passport-details-cloned')
) {
setText(subTitleElement, `${subTitleElement.innerText} ${fan.name}`);
} else {
setText(titleElement, `${titleElement.innerText} ${fan.name}`);
}
selectedElement.setAttribute('data-fan', fan.fan);
selectedElement.setAttribute('data-individual-id', fan.individualid);
return modifiedElement;
};
const generateNodes = (parentElement, juniors) => {
const registrationContainer = parentElement;
const components = [];
const [
uploadPassport,
passportDetails,
uploadProfile,
] = registrationContainer.querySelectorAll(
'.registration-upload-passport, .registration-passport-details, .registration-upload-profile'
);
juniors.forEach(fan => {
components.push(
modifyElement(
cloneElement(uploadPassport),
'.registration-upload-passport__upload-passport-photo .cta',
fan
)
);
components.push(
modifyElement(
cloneElement(passportDetails),
'.next-to-step-5 .cta',
fan
)
);
components.push(
modifyElement(
cloneElement(uploadProfile),
'.registration-upload-profile__next_btn .cta',
fan
)
);
});
return components;
};
const nextBtnClickHandler = (event, currElement, juniors, nextBtn) => {
const { parentElement } = currElement;
event.preventDefault();
if (nextBtn.classList.contains('cta--r-primary')) {
removePreviousNodes(parentElement);
const newNodes = generateNodes(parentElement, juniors);
newNodes.forEach(node => {
parentElement.appendChild(node);
});
const uploadPassport = currentElement.parentElement.querySelectorAll(
'.registration-upload-passport-cloned'
);
const passportDetails = currentElement.parentElement.querySelectorAll(
'.registration-passport-details-cloned'
);
const uploadProfile = currentElement.parentElement.querySelectorAll(
'.registration-upload-profile-cloned'
);
uploadPassport.forEach(element => {
registrationUploadPassport(element, element.nextElementSibling);
});
passportDetails.forEach(element => {
registrationPassportDetails(element);
});
uploadProfile.forEach(element => {
registrationUploadProfile(element);
});
nevigateToNext(currentElement);
}
};
const addBtnClickHandler = (e, addBtn) => {
e.preventDefault();
if (addBtn.classList.contains('cta--r-primary')) {
currentElement.classList.add(hideClass);
newRegisreation.classList.remove(hideClass);
}
};
onComponentVisible(currentElement, () => {
hideStep();
currentPage.page = currentElement;
showBackBtn();
controller.abort('Removing previous event listeners');
controller = new AbortController();
const selectAll = currentElement.querySelector(
'.registration-select-junior__selectAll'
);
const checkboxes = currentElement.querySelectorAll('input');
const [nextBtn, addbtn] = currentElement.querySelectorAll(
'.registration-select-junior__next a, .registration-select-junior__add a'
);
// removePreviousNodes(currentElement.parentElement);
checBoxCheckHandler(checkboxes, nextBtn);
selectAll.addEventListener(
'click',
event => selectAllClickHandler(event, checkboxes, nextBtn),
{ signal: controller.signal }
);
nextBtn.addEventListener(
'click',
event =>
nextBtnClickHandler(
event,
currentElement,
getSelectedJuniors(checkboxes),
nextBtn
),
{
signal: controller.signal,
}
);
addbtn.addEventListener('click', e => addBtnClickHandler(e, addbtn), {
signal: controller.signal,
});
checkboxes.forEach(checkBox => {
checkBox.addEventListener(
'change',
() => checBoxCheckHandler(checkboxes, nextBtn),
{ signal: controller.signal }
);
});
});
};
.registration-select-junior {
$cta-container-mt: 40px;
$cta-gap: 16px;
$body-mt: 32px;
.registration-select-junior__selectAll-container {
margin-bottom: 16px;
margin-top: $body-mt;
display: none;
.registration-select-junior__selectAll {
font-family: $registration-font;
font-weight: 400;
font-size: 16px;
line-height: 24px;
color: white;
cursor: pointer;
&:hover {
font-weight: 700;
}
}
}
.registration-select-junior__selectAll-container:has(+ div > .checkbox) {
display: block;
}
.cta-container {
margin-top: $cta-container-mt;
div:not(:first-child) {
margin-top: $cta-gap;
}
}
}
<div class="registration-select-junior registration_hide" data-junior="true">
<div class="registration-personal-details__title">
{{render '@registration-form-title' title}}
</div>
<div class="registration-personal-details__sub-title">
{{render '@registration-form-sub-title' sub-title}}
</div>
{{!-- adding error --}}
{{render '@registration-server-error'}}
<div class="registration-select-junior_list-container">
<div class="registration-select-junior__selectAll-container">
<a href="/" class="registration-select-junior__selectAll">Select all</a>
</div>
<div class="registration-select-junior_list">
{{render '@checkbox--with-dob' junior1 merge="true"}}
{{render '@checkbox--with-dob' junior2 merge="true"}}
{{render '@checkbox--with-dob' junior1 merge="true"}}
{{render '@checkbox--with-dob' junior2 merge="true"}}
{{render '@checkbox--with-dob' junior2 merge="true"}}
</div>
</div>
<div class="cta-container">
<div class="registration-select-junior__next">
{{render '@cta--r-disabled' next merge="true"}}
</div>
<div class="registration-select-junior__add">
{{render '@cta--r-disabled' new merge="true"}}
</div>
</div>
</div>