From 393d7b76481a48ad7a3cecbe07a3b942fc52c6ae Mon Sep 17 00:00:00 2001 From: uzquiano Date: Sun, 5 Jan 2020 20:18:41 -0500 Subject: [PATCH] Added SimpleMDE event inits, ensure that Array Field triggers propagated updates on add/remove/move --- src/js/fields/advanced/MarkdownField.js | 40 +++++++++++++++++++++++++ src/js/fields/basic/ArrayField.js | 27 +++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/src/js/fields/advanced/MarkdownField.js b/src/js/fields/advanced/MarkdownField.js index f15bdebab..d0e578b39 100644 --- a/src/js/fields/advanced/MarkdownField.js +++ b/src/js/fields/advanced/MarkdownField.js @@ -40,6 +40,44 @@ } }, + initMarkdownEditorEvents: function() + { + var self = this; + + if (self.editor) + { + self.editor.codemirror.on("change", function(e) { + self.onChange(); + self.triggerWithPropagation("change", e); + self.triggerWithPropagation("after_nested_change", e); + }); + + self.editor.codemirror.on("beforeChange", function(e) { + self.triggerWithPropagation("before_nested_change", e); + }); + + self.editor.codemirror.on("keyHandled", function(e) { + self.onKeyPress.call(self, e); + self.trigger("keypress", e); + }); + + self.editor.codemirror.on('blur', function (e) { + self.onBlur(); + self.trigger("blur", e); + }); + + self.editor.codemirror.on("focus", function (e) { + self.onFocus.call(self, e); + self.trigger("focus", e); + }); + + self.editor.codemirror.on("mousedown", function (e) { + self.onClick.call(self, e); + self.trigger("click", e); + }); + } + }, + afterRenderControl: function(model, callback) { var self = this; @@ -57,6 +95,8 @@ { self.editor = new SimpleMDE(self.options.markdown); } + + self.initMarkdownEditorEvents(); }); } diff --git a/src/js/fields/basic/ArrayField.js b/src/js/fields/basic/ArrayField.js index 5f987fa02..9d9bc92f6 100644 --- a/src/js/fields/basic/ArrayField.js +++ b/src/js/fields/basic/ArrayField.js @@ -1394,6 +1394,9 @@ if (self._validateEqualMaxItems()) { + // propagate up with "before_nested_change" + self.triggerWithPropagation("before_nested_change"); + self.createItem(index, schema, options, data, function(item) { // register the child @@ -1417,6 +1420,12 @@ // trigger update self.triggerUpdate(); + self.onChange.call(self); + self.triggerWithPropagation("change"); + + // propagate up with "after_nested_change" + self.triggerWithPropagation("after_nested_change"); + if (callback) { Alpaca.nextTick(function() { @@ -1463,6 +1472,9 @@ if (this._validateEqualMinItems() || force) { + // propagate up with "before_nested_change" + self.triggerWithPropagation("before_nested_change"); + // unregister the child self.unregisterChild(childIndex); @@ -1484,6 +1496,12 @@ // trigger update self.triggerUpdate(); + self.onChange.call(self); + self.triggerWithPropagation("change"); + + // propagate up with "after_nested_change" + self.triggerWithPropagation("after_nested_change"); + if (callback) { Alpaca.nextTick(function() { @@ -1558,6 +1576,9 @@ var onComplete = function() { + // propagate up with "before_nested_change" + self.triggerWithPropagation("before_nested_change"); + var adjustedTargetIndex = targetIndex; if (sourceIndex < targetIndex) { adjustedTargetIndex--; @@ -1584,6 +1605,12 @@ // dispatch event: move self.trigger("move"); + self.onChange.call(self); + self.triggerWithPropagation("change"); + + // propagate up with "after_nested_change" + self.triggerWithPropagation("after_nested_change"); + if (callback) { Alpaca.nextTick(function() {