Skip to content

Commit

Permalink
Wizard: Add beforeNext conditions to Details step footer
Browse files Browse the repository at this point in the history
This adds beforeNext condition to the custom Details step footer, allowing to validate after clicking Next. That way the button is enabled, but gets disabled in the case validation errors and the helper text with the error renders immediately.
  • Loading branch information
regexowl committed Oct 7, 2024
1 parent b4ac543 commit 4550bc7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Components/CreateImageWizard/CreateImageWizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ const CreateImageWizard = ({ isEdit }: CreateImageWizardProps) => {
// Firstboot
const firstBootValidation = useFirstBootValidation();
// Details
const [detailsPristine, setDetailsPristine] = useState(true);
const detailsValidation = useDetailsValidation();

let startIndex = 1; // default index
Expand Down Expand Up @@ -453,7 +454,14 @@ const CreateImageWizard = ({ isEdit }: CreateImageWizardProps) => {
status={detailsValidation.disabledNext ? 'error' : 'default'}
footer={
<CustomWizardFooter
disableNext={detailsValidation.disabledNext}
beforeNext={() => {
if (detailsValidation.disabledNext) {
setDetailsPristine(false);
return false;
}
return true;
}}
disableNext={!detailsPristine && detailsValidation.disabledNext}
/>
}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ describe('Step Details', () => {
const nextButton = await getNextButton();
expect(nextButton).toBeEnabled();
await enterBlueprintName(' ');
await clickNext();
await waitFor(() => expect(nextButton).toBeDisabled());
});

Expand All @@ -83,6 +84,7 @@ describe('Step Details', () => {
await goToDetailsStep();
await enterBlueprintName('Lemon Pie');
const nextButton = await getNextButton();
await clickNext();
await waitFor(() => expect(nextButton).toBeDisabled());
});

Expand Down

0 comments on commit 4550bc7

Please sign in to comment.