Skip to content

Commit

Permalink
Added SimpleMDE event inits, ensure that Array Field triggers propaga…
Browse files Browse the repository at this point in the history
…ted updates on add/remove/move
  • Loading branch information
cloudcms committed Jan 6, 2020
1 parent f5157ec commit 393d7b7
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/js/fields/advanced/MarkdownField.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -57,6 +95,8 @@
{
self.editor = new SimpleMDE(self.options.markdown);
}

self.initMarkdownEditorEvents();
});
}

Expand Down
27 changes: 27 additions & 0 deletions src/js/fields/basic/ArrayField.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {
Expand Down Expand Up @@ -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);

Expand All @@ -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() {
Expand Down Expand Up @@ -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--;
Expand All @@ -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() {
Expand Down

0 comments on commit 393d7b7

Please sign in to comment.