Skip to content

Commit daa8f84

Browse files
committed
MC-3917: Reset button doesn't work
1 parent 52555f1 commit daa8f84

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

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

Lines changed: 42 additions & 2 deletions
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.'),
@@ -43,16 +44,52 @@ define([
4344
}
4445
},
4546
listens: {
46-
id: 'updateFromServer'
47+
id: 'updateFromServer',
48+
'${ $.provider }:data.reset': 'reset'
4749
}
4850
},
4951

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+
5077
/**
5178
* @inheritdoc
5279
*/
5380
initObservable: function () {
5481
return this._super()
55-
.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);
5693
},
5794

5895
/**
@@ -90,6 +127,9 @@ define([
90127
}
91128

92129
this.meta(response);
130+
if (this.initialValue() === false) {
131+
this.initialValue(response)
132+
}
93133
}.bind(this))
94134
.fail(function () {
95135
this.meta({});

0 commit comments

Comments
 (0)