widgets: resolveProp: preserve numbers and booleans as strings in object values
This commit is contained in:
parent
4c008099ca
commit
c59c4a8065
3 changed files with 16 additions and 4 deletions
|
|
@ -567,7 +567,7 @@ class Widget extends EventEmitter {
|
|||
|
||||
}
|
||||
|
||||
resolveProp(propName, propValue, storeLinks=true, originalWidget, originalPropName, context) {
|
||||
resolveProp(propName, propValue, storeLinks=true, originalWidget, originalPropName, context, recursive) {
|
||||
|
||||
propValue = propValue !== undefined ? propValue : deepCopy(this.props[propName])
|
||||
originalWidget = originalWidget || this
|
||||
|
|
@ -886,7 +886,14 @@ class Widget extends EventEmitter {
|
|||
propValue = propValue.replace(new RegExp(k, 'g'), v)
|
||||
}
|
||||
|
||||
if (isJSON(propValue) && (propName !== 'label' || propValue === 'false')) {
|
||||
if (
|
||||
// json heuristic
|
||||
isJSON(propValue) &&
|
||||
// allow "false" string in label
|
||||
(propName !== 'label' || propValue === 'false') &&
|
||||
// don't coerce booleans and numbers as strings in objects
|
||||
(!recursive || (isNaN(propValue) && propValue != 'true' && propValue != 'false'))
|
||||
) {
|
||||
try {
|
||||
propValue = JSON.parse(propValue)
|
||||
} catch (err) {}
|
||||
|
|
@ -894,7 +901,7 @@ class Widget extends EventEmitter {
|
|||
|
||||
} else if (propValue != null && typeof propValue == 'object') {
|
||||
for (let k in propValue) {
|
||||
propValue[k] = this.resolveProp(propName, propValue[k], storeLinks, originalWidget, originalPropName, context)
|
||||
propValue[k] = this.resolveProp(propName, propValue[k], storeLinks, originalWidget, originalPropName, context, true)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue