Commit c4968950 authored by Evan W. Patton's avatar Evan W. Patton Committed by Jeffrey Schiller

Fix logic bug when property value is the empty string (#1618)

The conditional properties change added the ability to use a default
value when a property isn't specified. However, there is a logic bug
due to the fact that the empty string is falsey in JavaScript. This
fix also checks specifically for the empty string as well so that the
default value will be sent.
parent 60166322
...@@ -345,6 +345,15 @@ Blockly.ComponentDatabase.prototype.populateTypes = function(componentInfos) { ...@@ -345,6 +345,15 @@ Blockly.ComponentDatabase.prototype.populateTypes = function(componentInfos) {
info.setPropertyList.push(property.name); info.setPropertyList.push(property.name);
} }
} }
// Copy the designer property information to the block information
for (j = 0; property = componentInfo.properties[j]; ++j) {
var target = info.properties[property['name']];
// All designer properties should have setters, but if not...
if (!target) continue;
Object.keys(property).forEach(function(k) {
target[k] = property[k];
});
}
} }
}; };
......
...@@ -400,8 +400,12 @@ Blockly.Yail.getPropertySettersLines = function(componentJson, componentName, co ...@@ -400,8 +400,12 @@ Blockly.Yail.getPropertySettersLines = function(componentJson, componentName, co
propsToSend.forEach(function(prop) { propsToSend.forEach(function(prop) {
var info = type['properties'][prop]; var info = type['properties'][prop];
if (shouldSendProperty(prop, info)) { if (shouldSendProperty(prop, info)) {
var value = componentJson[prop];
if (!Boolean(value) && value !== '') {
value = info['defaultValue'];
}
code.push(Blockly.Yail.getPropertySetterString(componentName, componentJson['$Type'], prop, code.push(Blockly.Yail.getPropertySetterString(componentName, componentJson['$Type'], prop,
componentJson[prop] || info['defaultValue'], componentDb)); value, componentDb));
} }
}); });
return code; return code;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment