Skip to content

Commit c9cdda1

Browse files
committed
Fixed creating an tax category inline on the tax rate page
1 parent a35f1d7 commit c9cdda1

2 files changed

Lines changed: 28 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- Fixed a PHP error that could occur when processing a payment. ([#3092](https://github.com/craftcms/commerce/issues/3092))
66
- Fixed a bug that could occur when forgetting a cart. ([#3091](https://github.com/craftcms/commerce/pull/3091))
7+
- Fixed a bug that occurred when creating a tax category inline on the Edit Tax Rate page.
78

89
## 4.2.5.1 - 2023-02-02
910

src/templates/tax/taxrates/_fields.twig

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,22 @@
77

88
{% js %}
99
(function() {
10-
var $select = $('#{{ selectParams.id }}').selectize({
10+
taxRatesSelects['{{ selectParams.id }}'] = $('#{{ selectParams.id }}').selectize({
1111
dropdownParent: 'body'
1212
});
1313

14-
var selectize = $select.get(0).selectize;
14+
taxRatesSelectize['{{ selectParams.id }}'] = taxRatesSelects['{{ selectParams.id }}'].get(0).selectize;
1515

16-
selectize.addOption({
16+
taxRatesSelectize['{{ selectParams.id }}'].addOption({
1717
value: 'new',
1818
text: '{{ newOptionLabel|e("js") }}'
1919
});
2020

21-
selectize.on('item_add', function(value, $item) {
21+
taxRatesSelectize['{{ selectParams.id }}'].on('item_add', function(value, $item) {
2222
if (value == 'new') {
23+
var _this = this;
2324
// Not a real option
24-
selectize.clear();
25+
_this.clear();
2526

2627
var $form = $(
2728
'<form class="modal lazy-create-modal">' +
@@ -74,13 +75,24 @@
7475
$form.find('.spinner').addClass('hidden');
7576
Craft.cp.displayNotice('{{ successText|e("js") }}');
7677

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
8193
});
8294

83-
selectize.setValue(response.data.id);
95+
_this.setValue(data.id);
8496
modal.hide();
8597

8698
})
@@ -260,6 +272,11 @@
260272
</div>
261273
</div>
262274

275+
{% js at head %}
276+
var taxRatesSelects = {};
277+
var taxRatesSelectize = {};
278+
{% endjs %}
279+
263280
{% js %}
264281
{% if taxablesNoTaxCategory is defined and taxablesNoTaxCategory|length %}
265282
(function() {

0 commit comments

Comments
 (0)