Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions cms/static/js/views/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,18 @@ define(

/**
* Returns just the modified metadata values, in the format used to persist to the server.
* Set `replaceNullWithDefault` to true to replace null values with the default values
*/
getModifiedMetadataValues: function() {
getModifiedMetadataValues: function(replaceNullWithDefault = false) {
var modified_values = {};
this.collection.each(
function(model) {
if (model.isModified()) {
modified_values[model.getFieldName()] = model.getValue();
let value = model.getValue();
if (replaceNullWithDefault && value === null) {
value = model.getDisplayValue();
}
modified_values[model.getFieldName()] = value
}
}
);
Expand Down
5 changes: 3 additions & 2 deletions cms/static/js/views/xblock_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,11 @@ function($, _, gettext, BaseView, XBlockView, MetadataView, MetadataCollection)
/**
* Returns the metadata that has changed in the editor. This is a combination of the metadata
* modified in the "Settings" editor, as well as any custom metadata provided by the component.
* Set `replaceNullWithDefault` to true to replace null values with the default values.
*/
getChangedMetadata: function() {
getChangedMetadata: function(replaceNullWithDefault = false) {
var metadataEditor = this.getMetadataEditor();
return _.extend(metadataEditor.getModifiedMetadataValues(), this.getCustomMetadata());
return _.extend(metadataEditor.getModifiedMetadataValues(replaceNullWithDefault), this.getCustomMetadata());
},

/**
Expand Down
2 changes: 1 addition & 1 deletion common/templates/xblock_v2/xblock_iframe.html
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@
$('.save-button', passElement).bind('click', function() {
//event.preventDefault();
var error_message_div = $('.xblock-editor-error-message', passElement);
const modifiedData = editorView.getChangedMetadata();
const modifiedData = editorView.getChangedMetadata(true);

error_message_div.html();
error_message_div.css('display', 'none');
Expand Down