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 Sep 25, 2024
1 parent a796630 commit 31abc03
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 @@ -200,6 +200,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 @@ -450,7 +451,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('validates name', () => {
const nextButton = await getNextButton();
expect(nextButton).toBeEnabled();
await enterBlueprintName(' ');
await clickNext();
await waitFor(() => expect(nextButton).toBeDisabled());
});

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

Expand Down

0 comments on commit 31abc03

Please sign in to comment.