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