Skip to content

Commit

Permalink
FORMS-9362: loading icon behind fields (#880)
Browse files Browse the repository at this point in the history
* FORMS-9362: loading icon behind fields

* FORMS-9362 : null check added as per comments

* FORMS-9362 : changes due to review comments

* FORMS-9362 : formatting the changes
  • Loading branch information
AnurudraS authored and Shivam Agarwal committed Oct 3, 2023
1 parent 54f671a commit b810bda
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,5 @@ BLOCK cmp-adaptiveform-container
## JavaScript Data Attribute Bindings

Apply a `data-cmp-is="adaptiveFormContainer"` attribute to the `cmp-adaptiveform-container` block to enable initialization of the JavaScript component.

Applying `data-cmp-adaptiveform-container-loader` attribute to the div specifically for applying the loader class on it, it is to ensure that the loading icon should not appear over components.
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,20 @@
const startTime = new Date().getTime();
let elements = document.querySelectorAll(FormContainerV2.selectors.self);
for (let i = 0; i < elements.length; i++) {
elements[i].classList.add(FormContainerV2.loadingClass);
let loaderToAdd = document.querySelector("[data-cmp-adaptiveform-container-loader='"+ elements[i].id + "']");
if(loaderToAdd){
loaderToAdd.classList.add(FormContainerV2.loadingClass);
}
console.debug("Form loading started", elements[i].id);
}
function onInit(e) {
let formContainer = e.detail;
let formEl = formContainer.getFormElement();
setTimeout(() => {
formEl.classList.remove(FormContainerV2.loadingClass);
let loaderToRemove = document.querySelector("[data-cmp-adaptiveform-container-loader='"+ formEl.id + "']");
if(loaderToRemove){
loaderToRemove.classList.remove(FormContainerV2.loadingClass);
}
const timeTaken = new Date().getTime() - startTime;
console.debug("Form loading complete", formEl.id, timeTaken);
}, 10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@
<sly data-sly-use="${'removeattribute.js' @ referencedPage }"/>
</div>
</form>

<div data-cmp-adaptiveform-container-loader="${container.id}"></div>
17 changes: 14 additions & 3 deletions ui.tests/test-module/libs/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,14 +338,20 @@ const waitForFormInit = () => {
cy.get('form').then(($form) => {
const promise = new Cypress.Promise((resolve, reject) => {
const listener1 = e => {
if(document.querySelector("[data-cmp-adaptiveform-container-loader='"+ $form[0].id + "']").classList.contains("cmp-adaptiveform-container--loading")){
const isReady = () => {
if (!($form[0].classList.contains("cmp-adaptiveform-container--loading"))) {
const container = document.querySelector("[data-cmp-adaptiveform-container-loader='"+ $form[0].id + "']");
if (container &&
e.detail._path === $form.data("cmp-path") &&
!container.classList.contains("cmp-adaptiveform-container--loading")) {

resolve(e.detail);
}
setTimeout(isReady, 0)
}
isReady();
}
}
document.addEventListener(INIT_EVENT, listener1);
})
return promise
Expand All @@ -360,15 +366,20 @@ const waitForFormInitMultipleContiners = () => {
cy.get('form').each(($form) => {
const promise = new Cypress.Promise((resolve, reject) => {
const listener1 = e => {
if(document.querySelector("[data-cmp-adaptiveform-container-loader='"+ $form[0].id + "']").classList.contains("cmp-adaptiveform-container--loading")){
const isReady = () => {
if (e.detail._path === $form.data("cmp-path") &&
!($form[0].classList.contains("cmp-adaptiveform-container--loading"))) {
const container = document.querySelector("[data-cmp-adaptiveform-container-loader='"+ $form[0].id + "']");
if (container &&
e.detail._path === $form.data("cmp-path") &&
!container.classList.contains("cmp-adaptiveform-container--loading")) {

resolve(e.detail);
}
setTimeout(isReady, 0)
}
isReady();
}
}
document.addEventListener(INIT_EVENT, listener1);
})

Expand Down

0 comments on commit b810bda

Please sign in to comment.