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 Aug 29, 2024
1 parent e38ffe4 commit 7f3de68
Showing 1 changed file with 9 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 @@ -190,6 +190,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 @@ -424,7 +425,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

0 comments on commit 7f3de68

Please sign in to comment.