Skip to content

Commit 2c81dbe

Browse files
committed
Merge branch 'MC-1413' of github.com:magento-trigger/magento2-page-builder into MC-1413
2 parents 3c21301 + daa8f84 commit 2c81dbe

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

app/code/Magento/PageBuilder/view/adminhtml/web/js/form/element/block-chooser.js

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ define([
1818
meta: {},
1919
errorMessage: null,
2020
displayMetadata: true,
21+
initialValue: {},
2122
messages: {
2223
UNKOWN_ERROR: $t('Sorry, there was an error getting requested content. ' +
2324
'Please contact the store owner.'),
@@ -48,12 +49,47 @@ define([
4849
}
4950
},
5051

52+
/**
53+
* Invokes initialize method of parent class,
54+
* contains initialization logic
55+
*/
56+
initialize: function () {
57+
_.bindAll(this, 'reset');
58+
59+
this._super()
60+
.setInitialValue();
61+
62+
return this;
63+
},
64+
65+
/**
66+
* Sets initial value of the element and subscribes to it's changes.
67+
*
68+
* @returns {Abstract} Chainable.
69+
*/
70+
setInitialValue: function () {
71+
if (this.id()) {
72+
this.initialValue(false);
73+
}
74+
return this;
75+
},
76+
5177
/**
5278
* @inheritdoc
5379
*/
5480
initObservable: function () {
5581
return this._super()
56-
.observe('id meta errorMessage displayMetadata');
82+
.observe('id meta errorMessage displayMetadata initialValue');
83+
},
84+
85+
/**
86+
* Resets metadata
87+
*
88+
* @returns void
89+
*/
90+
reset: function () {
91+
this.meta(this.initialValue());
92+
this.errorMessage(null);
5793
},
5894

5995
/**
@@ -100,6 +136,9 @@ define([
100136
}
101137

102138
this.meta(response);
139+
if (this.initialValue() === false) {
140+
this.initialValue(response)
141+
}
103142
}.bind(this))
104143
.fail(function () {
105144
this.meta({});

0 commit comments

Comments
 (0)