Skip to content

Commit fee101a

Browse files
committed
fix(common): wizard check validating on enter
1 parent 02bba75 commit fee101a

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

packages/common/src/wizard/enter-handler.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ const enterHandler = (e, formOptions, activeStep, findCurrentStep, handleNext, h
1515
nextStep = selectNext(schemaNextStep, formOptions.getState);
1616
}
1717

18-
if (formOptions.valid && nextStep && !hasCustomButtons) {
18+
const canContinue = formOptions.valid && !formOptions.getState().validating;
19+
20+
if (canContinue && nextStep && !hasCustomButtons) {
1921
handleNext(nextStep, formOptions.getRegisteredFields);
20-
} else if (formOptions.valid && !schemaNextStep && !hasCustomButtons) {
22+
} else if (canContinue && !schemaNextStep && !hasCustomButtons) {
2123
handleSubmit();
2224
}
2325
}

packages/pf4-component-mapper/src/tests/wizard/step-buttons.test.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,9 @@ describe('<WizardSTepButtons', () => {
200200
preventDefault: jest.fn()
201201
};
202202
formOptions = {
203-
getState: jest.fn(),
204203
valid: true,
205-
getRegisteredFields
204+
getRegisteredFields,
205+
getState: () => ({ validating: false })
206206
};
207207
activeStep = 'active-step';
208208
findCurrentStep = jest.fn().mockImplementation(() => ({ nextStep }));
@@ -238,6 +238,34 @@ describe('<WizardSTepButtons', () => {
238238
expect(handleSubmit).not.toHaveBeenCalled();
239239
});
240240

241+
it('should be prevented if form is not valid', () => {
242+
formOptions = {
243+
valid: false,
244+
getRegisteredFields,
245+
getState: () => ({ validating: false })
246+
};
247+
248+
handleEnter(event, formOptions, activeStep, findCurrentStep, handleNext, handleSubmit);
249+
250+
expect(event.preventDefault).toHaveBeenCalled();
251+
expect(handleNext).not.toHaveBeenCalled();
252+
expect(handleSubmit).not.toHaveBeenCalled();
253+
});
254+
255+
it('should be prevented if form is validating', () => {
256+
formOptions = {
257+
valid: true,
258+
getRegisteredFields,
259+
getState: () => ({ validating: true })
260+
};
261+
262+
handleEnter(event, formOptions, activeStep, findCurrentStep, handleNext, handleSubmit);
263+
264+
expect(event.preventDefault).toHaveBeenCalled();
265+
expect(handleNext).not.toHaveBeenCalled();
266+
expect(handleSubmit).not.toHaveBeenCalled();
267+
});
268+
241269
it('nothing happen when key is not enter', () => {
242270
event = {
243271
...event,

0 commit comments

Comments
 (0)