Skip to content

Commit 729d290

Browse files
committed
Actually re-render on data change
1 parent 699de04 commit 729d290

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

view/adminhtml/web/js/components/preview.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ define([
2020
allData: '${ $.provider }:data'
2121
}
2222
},
23+
basePrice: ko.observable(),
24+
options: ko.observableArray(),
2325
calculatedPrice: ko.observable(),
2426
calculatedSize: ko.observable(),
2527

@@ -35,10 +37,10 @@ define([
3537
},
3638

3739
selectedUsageOptionsChanged: function(changed) {
38-
var price = this.allData.price;
40+
var price = this.basePrice();
3941
var size_id = this.allData.size_id;
40-
for( var index in this.allData.usage.options ) {
41-
if (this.allData.usage.options[index].type !== 'drop_down') {
42+
for( var index in this.options() ) {
43+
if (this.options()[index].type !== 'drop_down') {
4244
continue
4345
}
4446
var selectedOption = this.selectedUsageOptions[index]()
@@ -60,14 +62,26 @@ define([
6062
},
6163

6264
dataChanged: function( data ) {
63-
if ( ! this.selectedUsageOptions || ! data.usage || ! data.usage.options ) {
65+
if ( ! this.selectedUsageOptions || ! data || ! data.usage || ! data.usage.options ) {
6466
return;
6567
}
6668
for( var i = this.selectedUsageOptions.length; i < data.usage.options.length; i++ ) {
6769
var ob = ko.observable();
6870
ob.subscribe(this.selectedUsageOptionsChanged.bind(this));
6971
this.selectedUsageOptions.push(ob)
7072
}
73+
this.basePrice(data.price);
74+
var currentOptions = this.options();
75+
for (var i = 0; i < data.usage.options.length; i++) {
76+
if ( currentOptions[i] ) {
77+
if ( _(currentOptions[i]).isEqual(data.usage.options[i])) {
78+
continue;
79+
}
80+
this.options.splice(i, 1, data.usage.options[i]);
81+
} else {
82+
this.options.push(data.usage.options[i]);
83+
}
84+
}
7185
},
7286

7387
/**

view/adminhtml/web/template/form/components/preview.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11

22
<div class="admin__field-complex" style="margin: 0" css="$data.additionalClasses" attr="'data-index': index">
33

4-
<div class="admin__field-complex-title" if="allData.price">
4+
<div class="admin__field-complex-title" if="basePrice">
55
Preview
66
</div>
7-
<div class="admin__field-complex-title" if="allData.price">
8-
Base Price $<span text="allData.price"></span>
7+
<div class="admin__field-complex-title" if="basePrice">
8+
Base Price $<span text="basePrice"></span>
99
</div>
1010

1111
<div class=""
12-
each="data: allData.usage.options, as: 'option'"
12+
each="data: options, as: 'option'"
1313
>
1414
<div class="admin__field" style="margin:0" if="option.type === 'drop_down'">
1515
<div class="admin__field-label" style="text-align: left">

0 commit comments

Comments
 (0)