Skip to content
New issue

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

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

Already on GitHub? # to your account

Fixing issue where custom default value without a 'value=' within the script would return an empty string. #6049

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
31 changes: 3 additions & 28 deletions src/components/_classes/component/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,24 +387,6 @@
*/
this._referenceAttributeName = 'ref';

/**
* Sometimes the customDefaultValue does not set the "value" within the script, but is just a script to execute. This
* flag is used to determine if the customDefaultValue should be used to set the value of the component or not based on
* if there is a "value=" within the script.
*/
this.shouldSetCustomDefault = true;
if (this.component.customDefaultValue && (typeof this.component.customDefaultValue === 'string')) {
this.shouldSetCustomDefault = this.component.customDefaultValue.match(/value\s*=/);
}

/**
* Same as customDefaultValue, but for calculateValue.
*/
this.shouldSetCalculatedValue = true;
if (this.component.calculateValue && (typeof this.component.calculateValue === 'string')) {
this.shouldSetCalculatedValue = this.component.calculateValue.match(/value\s*=/);
}

/**
* Used to trigger a new change in this component.
* @type {Function} - Call to trigger a change in this component.
Expand Down Expand Up @@ -2918,14 +2900,11 @@

getCustomDefaultValue(defaultValue) {
if (this.component.customDefaultValue && !this.options.preview) {
const customDefaultValue = this.evaluate(
defaultValue = this.evaluate(
this.component.customDefaultValue,
{ value: '' },
{ value: this.dataValue },
'value'
);
if (this.shouldSetCustomDefault) {
defaultValue = customDefaultValue;
}
}
return defaultValue;
}
Expand Down Expand Up @@ -3044,7 +3023,7 @@

/**
* Returns if the value (e.g. array) should be divided between several inputs
* @returns {boolean}

Check warning on line 3026 in src/components/_classes/component/Component.js

View workflow job for this annotation

GitHub Actions / setup

Missing JSDoc @returns description
*/
isSingleInputValue() {
return false;
Expand Down Expand Up @@ -3218,18 +3197,14 @@
}

doValueCalculation(dataValue, data, row) {
const calculatedValue = this.evaluate(this.component.calculateValue, {
return this.evaluate(this.component.calculateValue, {
value: dataValue,
data,
row: row || this.data,
submission: this.root?._submission || {
data: this.rootValue
}
}, 'value');
if (this.shouldSetCalculatedValue) {
return calculatedValue;
}
return dataValue;
}

/* eslint-disable max-statements */
Expand Down
Loading