Skip to content

Commit

Permalink
FIO-8402: fixed an issue where Validation Triggering on initial Form …
Browse files Browse the repository at this point in the history
…load (#5625)

* FIO-8402: fixed an issue where Validation Triggering on initial Form Load

* FIO-8402: added test
  • Loading branch information
KatrinKhilko authored Jun 12, 2024
1 parent 3ae0d31 commit 3ceace6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
40 changes: 40 additions & 0 deletions src/Webform.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2297,6 +2297,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
2 changes: 1 addition & 1 deletion src/components/_classes/component/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -2972,7 +2972,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

0 comments on commit 3ceace6

Please sign in to comment.