Skip to content

Commit a635277

Browse files
regexowlmgold1234
authored andcommitted
Wizard: Add beforeNext conditions to Details step footer
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.
1 parent b1c5c62 commit a635277

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/Components/CreateImageWizard/CreateImageWizard.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ const CreateImageWizard = ({ isEdit }: CreateImageWizardProps) => {
203203
// Firstboot
204204
const firstBootValidation = useFirstBootValidation();
205205
// Details
206+
const [detailsPristine, setDetailsPristine] = useState(true);
206207
const detailsValidation = useDetailsValidation();
207208

208209
let startIndex = 1; // default index
@@ -453,7 +454,14 @@ const CreateImageWizard = ({ isEdit }: CreateImageWizardProps) => {
453454
status={detailsValidation.disabledNext ? 'error' : 'default'}
454455
footer={
455456
<CustomWizardFooter
456-
disableNext={detailsValidation.disabledNext}
457+
beforeNext={() => {
458+
if (detailsValidation.disabledNext) {
459+
setDetailsPristine(false);
460+
return false;
461+
}
462+
return true;
463+
}}
464+
disableNext={!detailsPristine && detailsValidation.disabledNext}
457465
/>
458466
}
459467
>

src/test/Components/CreateImageWizard/steps/Details/Details.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ describe('validates name', () => {
6363
const nextButton = await getNextButton();
6464
expect(nextButton).toBeEnabled();
6565
await enterBlueprintName(' ');
66+
await clickNext();
6667
await waitFor(() => expect(nextButton).toBeDisabled());
6768
});
6869

@@ -83,6 +84,7 @@ describe('validates name', () => {
8384
await goToDetailsStep();
8485
await enterBlueprintName('Lemon Pie');
8586
const nextButton = await getNextButton();
87+
await clickNext();
8688
await waitFor(() => expect(nextButton).toBeDisabled());
8789
});
8890

0 commit comments

Comments
 (0)