Skip to content

Commit f101db5

Browse files
authored
Fix minimum credit used (#222)
* Fix minimum credit used * update changelog * Fix wrong helper and quantity consumed field displayed without selected credit * Fix js error
1 parent 29d49c9 commit f101db5

3 files changed

Lines changed: 35 additions & 19 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## [unreleased] -
9+
10+
### Fixed
11+
12+
- Fix possibility to set 0 credit used when adding a follow-up, a task, or a solution
13+
814
## [1.15.2] - 2025-12-22
915

1016
### Fixed

templates/tickets/consume.html.twig

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,16 @@
6767

6868
{{ fields.numberField(
6969
'plugin_credit_quantity',
70-
0,
70+
1,
7171
__('Quantity consumed', 'credit'),
7272
{
7373
'entity': entity_id,
7474
'condition': condition,
7575
'max': default_credit_max,
76-
'min': 0,
76+
'min': 1,
77+
'disabled': not consume or not default_credit,
7778
'helper': __('Maximum consumable quantity', 'credit') ~ ' : <b>' ~ default_credit_max,
78-
'field_class': 'col-6 col-sm-6',
79+
'field_class': 'col-6 col-sm-6' ~ (not default_credit ? ' d-none' : ''),
7980
'input_class': 'col-xxl-5',
8081
'label_class': 'col-xxl-7',
8182
'rand': rand,
@@ -88,24 +89,31 @@
8889
function showCreditDiv{{ rand }}() {
8990
const creditVoucherBlock = document.getElementById('creditvoucherblock{{ rand }}');
9091
if (creditVoucherBlock) {
91-
creditVoucherBlock.style.display = creditVoucherBlock.style.display === 'none' ? 'block' : 'none';
92+
const isHidden = creditVoucherBlock.style.display !== 'none';
93+
creditVoucherBlock.style.display = isHidden ? 'none' : 'block';
94+
var consumeblock = document.querySelector('[name="credit_consume_{{ rand }}"]');
95+
var quantity = consumeblock.querySelector('[id*="plugin_credit_quantity_{{ rand }}"]');
96+
if (quantity) {
97+
quantity.disabled = isHidden;
98+
}
9299
}
93100
}
94101
95102
function getQuantityRemaining{{ rand }}(val) {
96-
consumeblock = document.querySelector('[name="credit_consume_{{ rand }}"]');
97-
quantity = consumeblock.querySelector('[id*="plugin_credit_quantity_{{ rand }}"]');
98-
quantity_label = consumeblock.querySelector('[for*="plugin_credit_quantity_{{ rand }}"]');
103+
var consumeblock = document.querySelector('[name="credit_consume_{{ rand }}"]');
104+
var quantity = consumeblock.querySelector('[id*="plugin_credit_quantity_{{ rand }}"]');
105+
var quantity_field = quantity.closest('.col-6');
106+
var quantity_label = consumeblock.querySelector('[for*="plugin_credit_quantity_{{ rand }}"]');
99107
if (val == 0) {
100-
quantity_label.style.display = 'none';
101-
quantity.style.display = 'none';
108+
quantity_field.classList.add('d-none');
109+
quantity.disabled = true;
102110
quantity.max = 0;
103111
quantity.value = 0;
104112
quantity_label.querySelector('span.form-help').setAttribute('data-bs-title', __('Maximum consumable quantity', 'credit') + ' : 0 ');
105113
quantity_label.querySelector('span.form-help').setAttribute('data-bs-content', __('Maximum consumable quantity', 'credit') + ' : 0 ');
106114
} else {
107-
quantity_label.style.display = 'block';
108-
quantity.style.display = 'block';
115+
quantity_field.classList.remove('d-none');
116+
quantity.disabled = false;
109117
110118
$.ajax({
111119
type: 'POST',
@@ -115,7 +123,7 @@
115123
}
116124
}).done(function (data) {
117125
quantity.max = data;
118-
quantity.value = 0;
126+
quantity.value = 1;
119127
quantity_label.querySelector('span.form-help').setAttribute('data-bs-title', __('Maximum consumable quantity', 'credit') + ' : <b>' + data);
120128
quantity_label.querySelector('span.form-help').setAttribute('data-bs-content', __('Maximum consumable quantity', 'credit') + ' : <b>' + data);
121129
});

templates/tickets/form.html.twig

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,29 +56,31 @@
5656

5757
{{ fields.numberField(
5858
'plugin_credit_quantity',
59-
0,
59+
1,
6060
__('Quantity consumed', 'credit'),
6161
{
6262
'entity': entity_id,
6363
'condition': conditions,
64-
'max': 0,
65-
'min': 0,
66-
'field_class': 'col-4 col-sm-4',
67-
'helper': __('Maximum consumable quantity', 'credit') ~ ' : <b>0 ',
64+
'min': 1,
65+
'field_class': 'col-4 col-sm-4 d-none',
66+
'helper': __('Maximum consumable quantity', 'credit'),
6867
}
6968
) }}
7069

7170
<script>
7271
function getQuantityRemainingForm(val) {
7372
var formblock = document.querySelector('.formblock');
7473
var quantity = formblock.querySelector('[id*="plugin_credit_quantity"]');
74+
var quantity_field = quantity.closest('.col-4');
7575
var quantity_label = formblock.querySelector('[for*="plugin_credit_quantity"]');
7676
7777
if (val == 0) {
78-
quantity.value = 0;
78+
quantity_field.classList.add('d-none');
79+
quantity.value = 1;
7980
quantity_label.querySelector('span.form-help').setAttribute('data-bs-title', __('Maximum consumable quantity', 'credit') + ' : 0 ');
8081
quantity_label.querySelector('span.form-help').setAttribute('data-bs-content', __('Maximum consumable quantity', 'credit') + ' : 0 ');
8182
} else {
83+
quantity_field.classList.remove('d-none');
8284
$.ajax({
8385
type: 'POST',
8486
url: '{{ path('plugins/credit/ajax/dropdownQuantity.php') }}',
@@ -87,7 +89,7 @@
8789
}
8890
}).done(function (data) {
8991
quantity.max = data;
90-
quantity.value = 0;
92+
quantity.value = 1;
9193
quantity_label.querySelector('span.form-help').setAttribute('data-bs-title', __('Maximum consumable quantity', 'credit') + ' : <b>' + data);
9294
quantity_label.querySelector('span.form-help').setAttribute('data-bs-content', __('Maximum consumable quantity', 'credit') + ' : <b>' + data);
9395
});

0 commit comments

Comments
 (0)