Skip to content

Commit

Permalink
Make sure we only validate the current page
Browse files Browse the repository at this point in the history
  • Loading branch information
lotorvik committed Dec 4, 2024
1 parent fbd7982 commit 77ef184
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
1 change: 0 additions & 1 deletion packages/fyllut/cypress/e2e/components/driving-list.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,6 @@ describe('DrivingList', () => {
cy.mocksUseRouteVariant('get-activities:success-empty');
cy.visit(`/fyllut/testdrivinglist/oppsummering?sub=digital&innsendingsId=a66e8932-ce2a-41c1-932b-716fc487813b`);
cy.defaultWaits();
cy.wait('@getActivities');
cy.wait('@getMellomlagring');

cy.get('.navds-alert').should('exist');
Expand Down
6 changes: 4 additions & 2 deletions packages/fyllut/cypress/e2e/form/focus-handling.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ describe('Focus handling', () => {
cy.get('[data-cy=error-summary]')
.should('exist')
.within(() => {
cy.findByRole('link', { name: 'Du må fylle ut: Hvilken type bolig bor du i?' }).should('exist').click();
cy.findByRole('link', { name: 'Du må fylle ut: Hvilken type bolig bor du i?' }).should('exist');
cy.findByRole('link', { name: 'Du må fylle ut: Hvilken type bolig bor du i?' }).click();
});

cy.findByRole('group', { name: 'Hvilken type bolig bor du i?' })
Expand All @@ -133,7 +134,8 @@ describe('Focus handling', () => {
cy.get('[data-cy=error-summary]')
.should('exist')
.within(() => {
cy.findByRole('link', { name: 'Du må fylle ut: Mottakers fornavn' }).should('exist').click();
cy.findByRole('link', { name: 'Du må fylle ut: Mottakers fornavn' }).should('exist');
cy.findByRole('link', { name: 'Du må fylle ut: Mottakers fornavn' }).click();
});
cy.findByRole('textbox', { name: 'Mottakers fornavn' }).should('have.focus').type('Max');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,10 @@ class BaseComponent extends FormioReactComponent {
*/
showErrorMessages() {
return (
this.root.currentPage?.nextPageClicked || this.root.submitted || this.builderMode || this.root.editFormDialog
(this.root.currentPage?.nextPageClicked && baseComponentUtils.isCurrentPanel(this)) ||
this.root.submitted ||
this.builderMode ||
this.root.editFormDialog
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,25 @@ const isReadOnly = (component?: Component, options?: ReactComponentType['options
);
};

const getParentPanel = (component: ReactComponentType) => {
if (!component.parent) {
return;
}

return component.parent?.type === 'components' ? component.parent : getParentPanel(component.parent);
};

const isCurrentPanel = (component: ReactComponentType) => {
return component.root.currentPage?.id === getParentPanel(component)?.id;
};

const baseComponentUtils = {
getId,
getLabel,
getHideLabel,
getEditFields,
isRequired,
isReadOnly,
isCurrentPanel,
};
export default baseComponentUtils;
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ interface ReactComponentType {
labelIsHidden(): boolean;
setCustomValidity(messages: string | string[] | ComponentError[], dirty?: boolean, external?: boolean): void;
isEmpty(value?: any): boolean;
parent?: ReactComponentType;
type: string;
// Element
id?: any;
emit(event: string, data: object): void;
Expand Down

0 comments on commit 77ef184

Please sign in to comment.