fix: clear buttons in advanced components editors in Libraries (#36752)

This commit is contained in:
Chris Chávez
2025-05-20 20:33:39 -05:00
committed by GitHub
parent 4b8bfe2307
commit 30ace04469
3 changed files with 11 additions and 5 deletions

View File

@@ -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
}
}
);

View File

@@ -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());
},
/**

View File

@@ -343,7 +343,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');