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-9524: Fix bad request when fetching nested form #5966

Closed
wants to merge 3 commits into from
Closed
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
18 changes: 8 additions & 10 deletions src/components/form/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default class FormComponent extends Component {
this.options.project = this.formSrc;
}
else {
this.formSrc = Formio.getProjectUrl();
this.formSrc = this.options.project || Formio.getProjectUrl();
this.options.project = this.formSrc;
}
if (this.component.form) {
Expand Down Expand Up @@ -161,10 +161,10 @@ export default class FormComponent extends Component {

// Make sure to not show the submit button in wizards in the nested forms.
_.set(options, 'buttonSettings.showSubmit', false);

// Set the parent option to the subform so those references are stable when the subform is created
options.parent = this;

if (!this.options) {
return options;
}
Expand Down Expand Up @@ -447,7 +447,7 @@ export default class FormComponent extends Component {
const componentsMap = this.componentsMap;
const formComponentsMap = this.subForm.componentsMap;
_.assign(componentsMap, formComponentsMap);
this.component.components = this.subForm.components.map((comp) => comp.component);
this.component.components = this.subForm.components.map((comp) => comp.component);
this.subForm.on('change', () => {
if (this.subForm) {
this.dataValue = this.subForm.getValue();
Expand Down Expand Up @@ -505,12 +505,10 @@ export default class FormComponent extends Component {
}
else if (this.formSrc) {
this.subFormLoading = true;
const options = this.root?.formio?.base && this.root?.formio?.projectUrl
? {
base: this.root.formio.base,
project: this.root.formio.projectUrl,
}
: {};
const options = {
base: this.root?.formio?.base || this.options.baseUrl || '',
project: this.root?.formio?.projectUrl || this.options.project || '',
};
return (new Formio(this.formSrc, options)).loadForm({ params: { live: 1 } })
.then((formObj) => {
this.formObj = formObj;
Expand Down
41 changes: 41 additions & 0 deletions test/unit/Form.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
comp6,
comp7,
comp8,
comp9,
nestedWizardForm,
} from './fixtures/form';
import Webform from '../../src/Webform.js';
Expand Down Expand Up @@ -535,3 +536,43 @@ describe('SaveDraft functionality for Nested Form', () => {
}).catch((err) => done(err));
});
});

describe('Rendering nested forms', () => {
const originalMakeRequest = Formio.makeRequest;
let urlRequests = [];

before((done) => {
Formio.makeRequest = (formio, type, url, method, data) => {
urlRequests.push(url);
return Promise.resolve({})
};
done();
});

afterEach(() => {
urlRequests = [];
});

after((done) => {
Formio.makeRequest = originalMakeRequest;
done();
});

const options = {
"baseUrl": "http://someHost",
"hooks": {},
"sanitize": true,
"readOnly": false,
"project": "http://soneHost/skpbdisfmqlnydv"
}
it('Should provide correct url for requsted nested form', (done) => {
const formElement = document.createElement('div');
Formio.createForm(formElement, comp9, options).then((form) => {
setTimeout(() => {
const isProjectIncluded = urlRequests.some(url => url.includes("skpbdisfmqlnydv"))
assert.equal(isProjectIncluded, true);
done()
600});
}).catch((err) => done(err));
});
});
51 changes: 51 additions & 0 deletions test/unit/fixtures/form/comp9.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
export default {
"name": "parent",
"path": "parent",
"type": "form",
"display": "form",
"components": [
{
"label": "Number",
"applyMaskOn": "change",
"mask": false,
"tableView": false,
"delimiter": false,
"requireDecimal": false,
"inputFormat": "plain",
"truncateMultipleSpaces": false,
"validateWhenHidden": false,
"key": "number",
"type": "number",
"input": true
},
{
"label": "Text Area",
"applyMaskOn": "change",
"autoExpand": false,
"tableView": true,
"validateWhenHidden": false,
"key": "textArea",
"conditional": {
"show": true,
"conjunction": "all",
"conditions": [
{
"component": "number",
"operator": "isEqual",
"value": 5
}]
},
"type": "textarea",
"input": true
},
{
"label": "Form",
"tableView": true,
"form": "676ec7413b531fd4c8986dc5",
"useOriginalRevision": false,
"key": "form",
"type": "form",
"input": true
}
],
}
3 changes: 2 additions & 1 deletion test/unit/fixtures/form/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import comp5 from './comp5';
import comp6 from './comp6';
import comp7 from './comp7';
import comp8 from './comp8';
import comp9 from './comp9';
import nestedWizardForm from './nestedWizardForm';
export { formModalEdit, comp1, comp2, comp3, comp4, comp5, comp6, comp7, comp8, nestedWizardForm };
export { formModalEdit, comp1, comp2, comp3, comp4, comp5, comp6, comp7, comp8, comp9, nestedWizardForm };

Loading