Commit 5c2eb224 by Braden MacDonald

Fixed fallback editor used for any unsupported but JSON-compatible fields

parent c0b0b141
......@@ -23,6 +23,13 @@ function StudioEditableXBlockMixin(runtime, element) {
return parseInt(val, 10);
if (type == "float")
return parseFloat(val);
if (type == "generic") {
val = val.trim();
if (val === "")
val = null;
else
val = JSON.parse(val); // TODO: handle parse errors
}
return val;
}
});
......@@ -33,7 +40,7 @@ function StudioEditableXBlockMixin(runtime, element) {
};
$field.bind("change input paste", fieldChanged);
$resetButton.click(function() {
$field.val($wrapper.data('default'));
$field.val($wrapper.attr('data-default')); // Use attr instead of data to force treating the default value as a string
$wrapper.removeClass('is-set');
$resetButton.removeClass('active').addClass('inactive');
});
......
......@@ -10,6 +10,7 @@ StudioEditableXBlockMixin to your XBlock.
# Imports ###########################################################
import json
import logging
from xblock.core import XBlock
......@@ -106,6 +107,10 @@ class StudioEditableXBlockMixin(object):
break
if "type" not in info:
raise NotImplementedError("StudioEditableXBlockMixin currently only supports fields derived from JSONField")
if info["type"] == "generic":
# Convert value to JSON string if we're treating this field generically:
info["value"] = json.dumps(info["value"])
info["default"] = json.dumps(info["default"])
if field.values and not isinstance(field, Boolean):
info['has_values'] = True
# This field has only a limited number of pre-defined options.
......
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