|
7 | 7 |
|
8 | 8 | {% js %} |
9 | 9 | (function() { |
10 | | - var $select = $('#{{ selectParams.id }}').selectize({ |
| 10 | + taxRatesSelects['{{ selectParams.id }}'] = $('#{{ selectParams.id }}').selectize({ |
11 | 11 | dropdownParent: 'body' |
12 | 12 | }); |
13 | 13 |
|
14 | | - var selectize = $select.get(0).selectize; |
| 14 | + taxRatesSelectize['{{ selectParams.id }}'] = taxRatesSelects['{{ selectParams.id }}'].get(0).selectize; |
15 | 15 |
|
16 | | - selectize.addOption({ |
| 16 | + taxRatesSelectize['{{ selectParams.id }}'].addOption({ |
17 | 17 | value: 'new', |
18 | 18 | text: '{{ newOptionLabel|e("js") }}' |
19 | 19 | }); |
20 | 20 |
|
21 | | - selectize.on('item_add', function(value, $item) { |
| 21 | + taxRatesSelectize['{{ selectParams.id }}'].on('item_add', function(value, $item) { |
22 | 22 | if (value == 'new') { |
| 23 | + var _this = this; |
23 | 24 | // Not a real option |
24 | | - selectize.clear(); |
| 25 | + _this.clear(); |
25 | 26 |
|
26 | 27 | var $form = $( |
27 | 28 | '<form class="modal lazy-create-modal">' + |
|
74 | 75 | $form.find('.spinner').addClass('hidden'); |
75 | 76 | Craft.cp.displayNotice('{{ successText|e("js") }}'); |
76 | 77 |
|
77 | | - selectize.addOption({ |
78 | | - value: response.data.id, |
79 | | - text: response.data.name, |
80 | | - $order: selectize.order - 1 |
| 78 | + if (!response.data) { |
| 79 | + return; |
| 80 | + } |
| 81 | + |
| 82 | + var data = {}; |
| 83 | + if (Object.keys(response.data).indexOf('taxCategory') !== -1) { |
| 84 | + data = response.data.taxCategory; |
| 85 | + } else { |
| 86 | + data = response.data.taxZone; |
| 87 | + } |
| 88 | + |
| 89 | + _this.addOption({ |
| 90 | + value: data.id, |
| 91 | + text: data.name, |
| 92 | + $order: _this.order - 1 |
81 | 93 | }); |
82 | 94 |
|
83 | | - selectize.setValue(response.data.id); |
| 95 | + _this.setValue(data.id); |
84 | 96 | modal.hide(); |
85 | 97 |
|
86 | 98 | }) |
|
260 | 272 | </div> |
261 | 273 | </div> |
262 | 274 |
|
| 275 | +{% js at head %} |
| 276 | + var taxRatesSelects = {}; |
| 277 | + var taxRatesSelectize = {}; |
| 278 | +{% endjs %} |
| 279 | + |
263 | 280 | {% js %} |
264 | 281 | {% if taxablesNoTaxCategory is defined and taxablesNoTaxCategory|length %} |
265 | 282 | (function() { |
|
0 commit comments