Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIO-9259 fixed errors list for parent wizard with nested wizard #5884

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Wizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ export default class Wizard extends Webform {
else {
this.currentPage.components.forEach((comp) => comp.setPristine(false));
this.scrollIntoView(this.element, true);
return Promise.reject(this.showErrors(errors, true));
return Promise.reject(super.showErrors(errors, true));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/form/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ export default class FormComponent extends Component {
options = options || {};
const silentCheck = options.silentCheck || false;

if (this.subForm) {
if (this.subForm && !this.isNestedWizard) {
return this.subForm.checkValidity(this.subFormData, dirty, null, silentCheck, errors);
}

Expand Down
53 changes: 53 additions & 0 deletions test/unit/Wizard.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,59 @@ describe('Wizard tests', () => {
.catch((err) => done(err));
});

it('should set correct errors list for parent wizard before clicking on the Next button', function(done) {
const formElement = document.createElement('div');
const wizard = new Wizard(formElement);
const nestedWizard = _.cloneDeep(wizardTestForm.form);
const parentWizardForm = _.cloneDeep(formWithNestedWizard);
parentWizardForm.components[1].components.push({
label: 'Parent Text',
applyMaskOn: 'change',
tableView: true,
validate: {
required: true
},
validateWhenHidden: false,
key: 'parentText',
type: 'textfield',
input: true
})
const clickEvent = new Event('click');

wizard.setForm(parentWizardForm).then(() => {
const nestedFormComp = wizard.getComponent('formNested');

nestedFormComp.loadSubForm = ()=> {
nestedFormComp.formObj = nestedWizard;
nestedFormComp.subFormLoading = false;
return new Promise((resolve) => resolve(nestedWizard));
};

nestedFormComp.createSubForm();

setTimeout(() => {
const clickWizardBtn = (pathPart) => {
const btn = _.get(wizard.refs, `${wizard.wizardKey}-${pathPart}`);
btn.dispatchEvent(clickEvent);
};

clickWizardBtn('link[1]');

setTimeout(() => {
assert.equal(wizard.page, 1, `Should open wizard page 2`);
clickWizardBtn('next');

setTimeout(() => {
assert.equal(wizard.errors.length, 1);
assert.equal(wizard.refs.errorRef.length, 1, 'Should have an error');
assert.equal(wizard.errors[0].message, 'Parent Text is required');
done();
}, 200);
}, 200);
}, 200)
})
.catch((err) => done(err));
})

it('Should execute advanced logic for wizard pages', function(done) {
const formElement = document.createElement('div');
Expand Down
Loading