Skip to content

Commit

Permalink
Allow clearing optional values in plugins
Browse files Browse the repository at this point in the history
Allow clearing out optional values on pluggable entities. Fixes #2108
  • Loading branch information
Edmundo Alvarez committed Apr 20, 2016
1 parent 2fae939 commit b49ba3f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static Map<String, Object> convertValues(final Map<String, Object> data,
final String type = (String) fieldDescription.get("type");

// Decide what to cast to. (string, bool, number)
final Object value;
Object value;
switch (type) {
case "text":
case "dropdown":
Expand All @@ -51,7 +51,12 @@ public static Map<String, Object> convertValues(final Map<String, Object> data,
try {
value = Integer.parseInt(String.valueOf(entry.getValue()));
} catch (NumberFormatException e) {
throw new ValidationException(field, e.getMessage());
// If a numeric field is optional and not provided, use null as value
if ("true".equals(String.valueOf(fieldDescription.get("is_optional")))) {
value = null;
} else {
throw new ValidationException(field, e.getMessage());
}
}
break;
case "boolean":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const ConfigurationForm = React.createClass({
data.configuration = {};

$.map(this.state.configFields, function(field, name) {
data.configuration[name] = (values[name] === undefined || values === null || String(values[name]).trim() === "" ? field.default_value : values[name]);
data.configuration[name] = values[name] || '';
});

return data;
Expand Down

0 comments on commit b49ba3f

Please sign in to comment.