Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@

constructor(params) {
super(params);
const {element} = params;
const {element, formContainer} = params;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formContainer is stored here but never guarded before use. If any caller constructs the wizard view without passing formContainer in params (e.g. a subclass, test harness, or future refactor), this.formContainer will be undefined and the setFocus call in #navigateToNextTab will throw. Consider either asserting it is present here (if (!formContainer) console.warn(...)) or using optional chaining at the call site.

this.formContainer = formContainer;
this.cacheElements(element);
this.setActive(this.getCachedTabs())
this._active = this.getActiveIndex(this.getCachedTabs());
Expand Down Expand Up @@ -232,6 +233,8 @@
if (tabs && nextVisibleIndex >= 0) {
this.#navigateAndFocusTab(nextVisibleIndex);
}
} else {
this.formContainer.setFocus(validationErrorList[0].fieldName);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No null guard on this.formContainer. If formContainer was not passed in params for any reason, this crashes with Cannot read properties of undefined (reading 'setFocus'). Safer as:

this.formContainer?.setFocus(validationErrorList[0].fieldName);

}
this.#hideUnhideNavButtons(this._active);
}
Expand Down
14 changes: 14 additions & 0 deletions ui.tests/test-module/specs/wizard/wizard.runtime.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,20 @@ describe("Form with Wizard Layout Container With Validation", () => {
})
})
});

it("should stay on current tab and show validation errors when next is clicked with invalid fields", () => {
getTabs().should('have.length', 5);
getWizardPanels().should('have.length', 5);
getTabAtIndex(0).should('have.class', 'cmp-adaptiveform-wizard__tab--active');
getWizardPanelAtIndex(0).should('have.class', 'cmp-adaptiveform-wizard__wizardpanel--active');
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test verifies the tab stays active and error messages appear, but the main new behavior — that focus moves to the first invalid field — is not asserted. The setFocus call is the entire point of this change. Consider adding something like:

// verify focus landed on the first invalid field
cy.focused().closest('[data-cmp-is]').should('have.attr', 'data-cmp-is');

or checking document.activeElement is within the first errored component. Without this, a regression in setFocus would not be caught by this test.


getNextButton().click({force: true}).then(() => {
getTabAtIndex(0).should('have.class', 'cmp-adaptiveform-wizard__tab--active');
getWizardPanelAtIndex(0).should('have.class', 'cmp-adaptiveform-wizard__wizardpanel--active');
getWizardPanelAtIndex(0).find('.cmp-adaptiveform-numberinput__errormessage').should('be.visible');
getWizardPanelAtIndex(0).find('.cmp-adaptiveform-datepicker__errormessage').should('be.visible');
});
});
});

describe("Form with Wizard Layout Container with focus", () => {
Expand Down
Loading