Skip to content

Commit

Permalink
Merge branch 'master' of github.com:formio/formio.js into dev.tt
Browse files Browse the repository at this point in the history
  • Loading branch information
travist committed Jun 18, 2024
2 parents 706b225 + d6c68eb commit 0850490
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 39 deletions.
7 changes: 7 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,13 @@ Formio.createForm(document.getElementById('formio'), 'https://examples.form.io/e
- FIO-8366: API key is not unique translation
- FIO-8433: fixed restore draft for nested forms
- FIO-8395: html in error message not evaluating
- FIO-7206: Fixes an issue where API keys of the removed components are not removed from the Data Grid defaultValue
- FIO-8402: fixed an issue where Validation Triggering on initial Form load
- Remove *zoom (IE7 hack)
- made Formio available globally
- FIO-8027 added new Captcha provider
- FIO-8281: fixed selectData property for multiple select component
- FIO-8420: file component no defaults causes error

## 5.0.0-rc.37
### Fixed
Expand Down
40 changes: 40 additions & 0 deletions src/Webform.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2294,6 +2294,46 @@ describe('Webform tests', function() {
});
});

it('Should not fire validation on calculated values init.', (done) => {
formElement.innerHTML = '';
const form = new Webform(formElement,{ language: 'en' });
form.setForm(
{ title: 'noValidation flag',
components: [{
label: 'minMax',
calculateValue: 'value = {minAmount: \'5.00\', maxAmount: \'50000.00\'};',
calculateServer: true,
key: 'minMax',
type: 'hidden',
input: true
}, {
label: 'A',
key: 'a',
type: 'number',
input: true
}, {
label: 'B',
key: 'b',
type: 'number',
input: true
}, {
label: 'Sum',
validate: {
required: true,
min: 10
},
calculateValue: 'var total = _.isNumber(data.a) ? data.a : 0;\ntotal += _.isNumber(data.b) ? data.b : 0;\n\nvalue = parseFloat(total.toFixed(2));',
calculateServer: true,
key: 'sum',
type: 'number',
input: true
}],
}
).then(() => {
checkForErrors(form, {}, { data: {} }, 0, done);
});
});

it('Should set calculated value correctly', (done) => {
formElement.innerHTML = '';
const form = new Webform(formElement);
Expand Down
10 changes: 8 additions & 2 deletions src/WebformBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -1131,8 +1131,14 @@ export default class WebformBuilder extends Component {
else if (parent.formioComponent && parent.formioComponent.removeChildComponent) {
parent.formioComponent.removeChildComponent(component);
}
if (component.input && componentInstance && componentInstance.parent) {
_.unset(componentInstance._data, componentInstance.key);
if (component.input && componentInstance && parent.formioComponent) {
const parentDefaultValue = _.get(parent.formioComponent, 'component.defaultValue', null);
if (Array.isArray(parentDefaultValue)) {
parentDefaultValue.forEach(v => _.unset(v, componentInstance.key));
}
else if (typeof parentDefaultValue === 'object') {
_.unset(parentDefaultValue, componentInstance.key);
}
}
const rebuild = parent.formioComponent.rebuild() || Promise.resolve();
rebuild.then(() => {
Expand Down
77 changes: 45 additions & 32 deletions src/WebformBuilder.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,40 +257,53 @@ describe('WebformBuilder tests', function() {

it('Should remove deleted components keys from default value', (done) => {
const builder = Harness.getBuilder();
builder.setForm({}).then(() => {
Harness.buildComponent('datagrid');
builder.setForm({
display: 'form',
type: 'form',
components: [
{
label: 'Data Grid',
reorder: false,
addAnotherPosition: 'bottom',
layoutFixed: false,
enableRowGroups: false,
initEmpty: false,
tableView: false,
defaultValue: [
{
textField: '',
},
],
validateWhenHidden: false,
key: 'dataGrid',
type: 'datagrid',
input: true,
components: [
{
label: 'Text Field',
applyMaskOn: 'change',
tableView: true,
validateWhenHidden: false,
key: 'textField',
type: 'textfield',
input: true,
},
],
},
],
}).then(() => {
const textField = builder.webform.getComponent(['dataGrid', 'textField'])[0];
textField.refs.removeComponent.dispatchEvent( new MouseEvent('click', {
view: window,
bubbles: true,
cancelable: true
}));

setTimeout(() => {
const dataGridDefaultValue = builder.editForm.getComponent('defaultValue');
dataGridDefaultValue.removeRow(0);

setTimeout(() => {
Harness.saveComponent();
setTimeout(() => {
const dataGridContainer = builder.webform.element.querySelector('[ref="dataGrid-container"]');
Harness.buildComponent('textfield', dataGridContainer);

setTimeout(() => {
Harness.saveComponent();

setTimeout(() => {
const textField = builder.webform.getComponent(['dataGrid', 'textField'])[0];
textField.refs.removeComponent.dispatchEvent( new MouseEvent('click', {
view: window,
bubbles: true,
cancelable: true
}));

setTimeout(() => {
const dataGrid = builder.webform.getComponent(['dataGrid']);
assert.deepEqual(dataGrid.schema.defaultValue, [{}], 'Should remove TextField key');
done();
}, 300);
});
}, 300);
}, 300);
}, 350);
}, 350);
const dataGrid = builder.webform.getComponent(['dataGrid']);
assert.deepEqual(dataGrid.schema.defaultValue, [{}], 'Should remove TextField key');
done();
}, 300);
}).catch(done);
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/components/_classes/component/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -3217,7 +3217,7 @@ export default class Component extends Element {
this.calculatedValue = fastCloneDeep(calculatedValue);

if (changed) {
if (!flags.noPristineChangeOnModified) {
if (!flags.noPristineChangeOnModified && this.root.initialized) {
this.pristine = false;
}

Expand Down
3 changes: 1 addition & 2 deletions src/components/file/File.js
Original file line number Diff line number Diff line change
Expand Up @@ -744,8 +744,7 @@ export default class FileComponent extends Field {
const fileWithSameNameUploading = this.filesToSync.filesToUpload
.some(fileToSync => fileToSync.file?.name === file.name);

const fileWithSameNameUploaded = this.dataValue
.some(fileStatus => fileStatus.originalName === file.name);
const fileWithSameNameUploaded = _.some(this.dataValue, fileStatus => fileStatus.originalName === file.name);

return fileWithSameNameUploaded || fileWithSameNameUploading
? {
Expand Down
6 changes: 6 additions & 0 deletions src/components/file/File.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,10 @@ describe('File Component', () => {
}, 100);
});
});
it('should not error on upload when noDefaults is set to true', () => {
return Formio.createForm(document.createElement('div'), comp2,{ noDefaults: true }).then((form)=>{
const file = form.getComponent('file');
return file.handleFilesToUpload([{ name: 'mypdf.pdf', size: 123123, type: 'application/pdf' }]);
});
});
});
4 changes: 2 additions & 2 deletions src/components/form/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ export default class FormComponent extends Component {
}
else if (this.formSrc) {
this.subFormLoading = true;
const options = this.root.formio?.base && this.root.formio?.projectUrl
const options = this.root?.formio?.base && this.root?.formio?.projectUrl
? {
base: this.root.formio.base,
project: this.root.formio.projectUrl,
Expand Down Expand Up @@ -714,7 +714,7 @@ export default class FormComponent extends Component {
if (shouldLoadSubmissionById || shouldLoadDraftById) {
const formId = submission.form || this.formObj.form || this.component.form;
const submissionUrl = `${this.subForm.formio.formsUrl}/${formId}/submission/${submission._id || this.subForm.submission._id}`;
const options = this.root.formio?.base && this.root.formio?.projectUrl
const options = this.root?.formio?.base && this.root?.formio?.projectUrl
? {
base: this.root.formio.base,
project: this.root.formio.projectUrl,
Expand Down

0 comments on commit 0850490

Please sign in to comment.